DBServer close in X#
Posted: Sat Oct 19, 2019 3:39 pm
Hello,
in my migrated VO applications I have noted that the DBServers are never closed, even when the using window is closed.
In VO, you can try this code:
and you will see that after the CollectForced() call there is no open workarea.
The same code in X# leaves the DBServer open.
Please see the following code (and the changed behavior of the DbServerEx class that has a destructor method):
Please find both the AEF and the XIDE export file attached to this message.
Wolfgang
P.S. I would map the CollectForced() function to a call of System.GC.Collect().
in my migrated VO applications I have noted that the DBServers are never closed, even when the using window is closed.
In VO, you can try this code:
Code: Select all
FUNCTION Start(p)
LOCAL sCmdLine := Psz2String(_GetCmdLine()) AS STRING
LOCAL oCon AS Console
oCon := Console{}
oCon:Clear()
oCon:Title := "Visual Objects Console Application."
oCon:WriteLine("CA-Visual Objects Basic Console Application.")
oCon:TextAttribute := FOREGROUND_WHITE
TestServer( oCon )
OpenAreas( oCon )
oCon:Write("Press Enter")
oCon:Read()
oCon:WriteLine( "execute CollectForced()" )
CollectForced()
OpenAreas( oCon )
oCon:Write("Press Enter")
oCon:Read()
RETURN NIL
function TestServer( oCon as Console ) as void pascal
local oDBServer as DBServer
oCon:WriteLine( "Open server...." )
oDBServer := DBServer{ "C:cavo28SamplesSsatutorcustomer.dbf", true, false, "DBFNTX" }
return
function OpenAreas( oCon as Console ) as void
local nCounter as dword
local cPath as string
for nCounter := 1023 downto 1
if VODBAlias( nCounter ) != NULL_STRING
cPath := AllTrim( ( nCounter )->( DBInfo( DBI_FULLPATH ) ) )
oCon:WriteLine( "Open:" + cPath )
endif
next
return
The same code in X# leaves the DBServer open.
Please see the following code (and the changed behavior of the DbServerEx class that has a destructor method):
Code: Select all
function Start( ) as void
TestServer()
OpenAreas()
System.Console.Write("Press Enter")
System.Console.Read()
System.Console.WriteLine( "execute CollectForced()" )
System.GC.Collect()
OpenAreas()
System.Console.Write("Press Enter")
System.Console.Read()
System.GC.Collect()
OpenAreas()
return
function TestServer() as void pascal
local oDBServer as DBServer
local oDBServerEx as DBServerEx
System.Console.WriteLine( "Open server...." )
oDBServer := DBServer{ "C:cavo28SamplesSsatutorcustomer.dbf", true, false, "DBFNTX" }
oDBServerEx := DBServerEx{ "C:cavo28SamplesSsatutorcustomer.dbf", true, false, "DBFNTX" }
return
function OpenAreas() as void
local nCounter as dword
local cPath as string
for nCounter := XSharp.RDD.WorkAreas.MaxWorkAreas downto 1
if VODBAlias( nCounter ) != NULL_STRING
cPath := AllTrim( ( nCounter )->( DBInfo( DBI_FULLPATH ) ) )
System.Console.WriteLine( "Open:" + cPath )
endif
next
return
class DBServerEx inherit DBServer
constructor( oFile as usual, lShareMode as usual, lReadOnlyMode as usual, xDriver as usual )
super( oFile, lShareMode, lReadOnlyMode, xDriver )
return
destructor()
System.Console.WriteLine( "Destructor called on class DBServerEx" )
if self:Used
self:Close()
endif
return
end class
P.S. I would map the CollectForced() function to a call of System.GC.Collect().