Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Failing to enter a critical section.
Message
From
06/07/2000 14:26:01
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
Failing to enter a critical section.
Miscellaneous
Thread ID:
00389023
Message ID:
00389023
Views:
47
Below is the code which is just a test of the critical section. Right now I am unable to enter. Can you see anything in the code below that I am doing incorrectly?

TIA
#DEFINE kcEol			CHR(13) + CHR(10)

DEFINE CLASS CriticalSection AS CUSTOM OLEPUBLIC

FUNCTION INIT

* DCC - Declare the needed API's for the critcal section.
DECLARE InitializeCriticalSection IN Kernel32 ;
	Integer @nHandle
	
DECLARE INTEGER EnterCriticalSection IN Kernel32 ;
	INTEGER @nHandle
	
DECLARE INTEGER TryEnterCriticalSection IN Kernel32 ;
	INTEGER @nHandle
	
DECLARE LeaveCriticalSection IN Kernel32 ;
	Integer @nHandle

lnHandle = 0

* DCC - First initialize the critical section and store the handle.
llSuccess = InitializeCriticalSection( @lnHandle )
IF lnHandle > 0
	=STRTOFILE( "1: " + TTOC( DATETIME() ) + " Succesfully Initalized Critical section" + kcEol, "D:\CriticalSectionLog.txt", .T. )
ELSE
	=STRTOFILE( "1: " + TTOC( DATETIME() ) + " Failed to Initalized Critical section" + kcEol, "D:\CriticalSectionLog.txt", .T. )	
	RETURN
ENDIF

* DCC - Then attempt to enter the critical section.
ltNow = DATETIME()
llSuccessfulEntry = .T.
DO WHILE TryEnterCriticalSection( @lnHandle ) = 0
	* DCC - Timeout after 10 seconds
	IF DATETIME() > ltNow + 10
		llSuccessfulEntry = .F.
		EXIT
	ENDIF
ENDDO

* DCC - Log success or failure
IF llSuccessfulEntry
	=STRTOFILE( "1: " + TTOC( DATETIME() ) + " Succesfully entered Critical section" + kcEol, "D:\CriticalSectionLog.txt", .T. )
ELSE
	=STRTOFILE( "1: " + TTOC( DATETIME() ) + " Failed to enter Critical section" + kcEol, "D:\CriticalSectionLog.txt", .T. )
	RETURN
ENDIF

* DCC - Leave criticla section.
=LeaveCriticalSection( @lnHandle )
=STRTOFILE( "1: " + TTOC( DATETIME() ) + " Left Critical section" + kcEol, "D:\CriticalSectionLog.txt", .T. )
ENDFUNC

ENDDEFINE
Reply
Map
View

Click here to load this message in the networking platform