Modify

Opened 14 years ago

Last modified 8 months ago

#1652 assigned Bug

Sleep in TimerFunc

Reported by: hunt Owned by: Jon
Milestone: Component: AutoIt
Version: 3.3.6.0 Severity: None
Keywords: Cc:

Description

Form does not close on the first try because of sleep in TimerFunc.

#Include <Timers.au3>
#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Form", 200, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "__Exit")
GUISetState()

_Timer_SetTimer($hGUI, 10, "__Timer")

While 1
    Sleep(10)
WEnd

Func __Timer($hWnd, $Msg, $iIDTimer, $dwTime)
	Sleep(1)
EndFunc

Func __Exit()
	_Timer_KillAllTimers($hGUI)
    Exit
EndFunc

Attachments (0)

Change History (16)

comment:1 Changed 14 years ago by hunt

I think when i trying to close script first time then script kills timer and stops before Exit. And when i trying to close script second time then script closes normally.

comment:2 Changed 14 years ago by Jpm

I found the problem. It is related really to Sleep().
The same problem can occur on ProcessWait(), ProcessWaitClose(), RunWait() RunAsWait() and ShellExecuteWait().
I intend to return failure on those when the situation occurs.

comment:3 Changed 14 years ago by anonymous

Jpm I think - this problem has not been if not executed function of timer before "Exit Function(s)". In example below TimerFunc not executes while calls function _Test in loop but executes before Exit! Why?

#Include <Timers.au3>
#include <GUIConstantsEx.au3>

Global $BeforeExit = 0

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Form", 200, 100)
GUICtrlCreateButton("test",4,4,100,50)
GUISetOnEvent($GUI_EVENT_CLOSE, "__Exit")
GUISetState()

_Timer_SetTimer($hGUI, 10, "__Timer")


While 1
    Sleep(10)
WEnd


Func __Timer($hWnd, $Msg, $iIDTimer, $dwTime)
	If $BeforeExit = 1 Then ConsoleWrite("Entered here before Exit" & @CRLF)
	;Sleep(1)
EndFunc


Func __Exit()
	_Timer_KillAllTimers($hGUI)
	$BeforeExit = 1
	For $i = 1 to 999999
		_Test()
	Next
    Exit
EndFunc


Func _Test()
EndFunc

comment:4 Changed 14 years ago by Jpm

This ticket is referenced in revision: [5862]

comment:5 Changed 14 years ago by Jpm

  • Milestone set to 3.3.7.0
  • Owner set to Jpm
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed by revision [5863] in version: 3.3.7.0

comment:6 Changed 14 years ago by Jpm

This ticket is referenced in revision: [5864]

comment:7 Changed 13 years ago by Jon

  • Resolution Fixed deleted
  • Status changed from closed to reopened

comment:8 Changed 13 years ago by TicketCleanup

  • Milestone 3.3.7.0 deleted

Automatic ticket cleanup.

comment:9 Changed 11 years ago by Jon

  • Resolution set to Rejected
  • Status changed from reopened to closed

comment:10 Changed 11 years ago by Jpm

  • Resolution Rejected deleted
  • Status changed from closed to reopened

comment:11 Changed 5 years ago by mLipok

here is my modified script:

#AutoIt3Wrapper_UseX64=Y
;~ #AutoIt3Wrapper_AutoIt3Dir="z:\AutoItPortable\AutoIt_3_3_15_3"
;~ #AutoIt3Wrapper_Aut2exe="z:\AutoItPortable\AutoIt_3_3_15_3\Aut2Exe\Aut2exe.exe"
;~ #AutoIt3Wrapper_AutoIt3="z:\AutoItPortable\AutoIt_3_3_15_3\AutoIt3.exe"

#Include <Timers.au3>
#include <GUIConstantsEx.au3>

Global $BeforeExit = 0

Opt("GUIOnEventMode", 1)

Global $hGUI = GUICreate("Form", 200, 100)
GUICtrlCreateButton("test",4,4,100,50)
GUISetOnEvent($GUI_EVENT_CLOSE, "__Exit")
GUISetState()

_Timer_SetTimer($hGUI, 10, "__Timer")


While 1
    Sleep(10)
WEnd


Func __Timer($hWnd, $Msg, $iIDTimer, $dwTime)
	#forceref $hWnd, $Msg, $iIDTimer, $dwTime
	If $BeforeExit = 1 Then ConsoleWrite("Entered here before Exit" & @CRLF)
	;Sleep(1)
EndFunc


Func __Exit()
	_Timer_KillAllTimers($hGUI)
	$BeforeExit = 1
	For $i = 1 to 999999
		_Test()
	Next
    Exit
EndFunc


Func _Test()
EndFunc

results in AutoIt 3.3.14.5 :

>Running:(3.3.14.5):Z:\AutoItPortable\App\autoit3_x64.exe "Z:\AutoItPortable\__COMUNITY\TRACK\TRACK_1652 Sleep in TimerFunc.au3"    
Entered here before Exit
!>23:16:19 AutoIt3.exe ended.rc:-1073741819

results in AutoIt 3.3.15.3 :

>Running:(3.3.15.3):z:\AutoItPortable\AutoIt_3_3_15_3\AutoIt3.exe "Z:\AutoItPortable\__COMUNITY\TRACK\TRACK_1652 Sleep in TimerFunc.au3"    
Entered here before Exit
+>23:17:30 AutoIt3.exe ended.rc:0

Is it fixed ?

Version 0, edited 5 years ago by mLipok (next)

comment:12 Changed 5 years ago by Jpm

I sure not as The pb mention by hunt is still true (click twice)
In the old time I propose a solution to Jon but he diskike the solution so reject the fix.
At that time I reopen the ticket so Jon can do Something he like.

comment:13 Changed 5 years ago by Jpm

  • Owner changed from Jpm to Jon
  • Status changed from reopened to assigned

comment:14 Changed 4 years ago by Jpm

  • Owner changed from Jon to Jpm

comment:15 Changed 17 months ago by anonymous

#AutoIt3Wrapper_UseX64=Y
;~ #AutoIt3Wrapper_AutoIt3Dir="z:\AutoItPortable\AutoIt_3_3_15_3"
;~ #AutoIt3Wrapper_Aut2exe="z:\AutoItPortable\AutoIt_3_3_15_3\Aut2Exe\Aut2exe.exe"
;~ #AutoIt3Wrapper_AutoIt3="z:\AutoItPortable\AutoIt_3_3_15_3\AutoIt3.exe"

#Include <Timers.au3>
#include <GUIConstantsEx.au3>

Global $BeforeExit = 0

Opt("GUIOnEventMode", 1)

Global $hGUI = GUICreate("Form", 200, 100)
GUICtrlCreateButton("test",4,4,100,50)
GUISetOnEvent($GUI_EVENT_CLOSE, "Exit")
GUISetState()

_Timer_SetTimer($hGUI, 10, "Timer")

While 1

Sleep(10)

WEnd

Func Timer($hWnd, $Msg, $iIDTimer, $dwTime)

#forceref $hWnd, $Msg, $iIDTimer, $dwTime
If $BeforeExit = 1 Then ConsoleWrite("Entered here before Exit" & @CRLF)
;Sleep(1)

EndFunc

Func Exit()

_Timer_KillAllTimers($hGUI)
$BeforeExit = 1
For $i = 1 to 999999

_Test()

Next

Exit

EndFunc

Func _Test()
EndFunc

comment:16 Changed 8 months ago by Jpm

  • Owner changed from Jpm to Jon

Both Hunt and mLipok pb solved
Fix sent to Jon

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as assigned The owner will remain Jon.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.