Sign in to follow this  
Followers 0
binhnx

If condition check in a interruptible function. Is it safe?

37 posts in this topic

#1 ·  Posted (edited)

Let start with some examples:

1. (As seen in another topic: '?do=embed' frameborder='0' data-embedContent>> ).

Script copied from that topic

Interrupt function can be any hotkey/event/adlib/callback.

If-check inside interrupted function/script 

; HotKeySet, or any function that can cause script interrupt
HotKeySet("{Delete}", "RemoveSelectedControl")

;...
Dim $InfoAboutControls[4096]
Global $HandleForCurrentControl
;...


While 1
    $msg = GuiGetMsg()
  ;....
    
  ;---Code to process moving a control (drag-n-drop)---
    ; If check in MAIN LOOP (interruptible function).
    If $HandleForCurrentControl > 0 Then;Make sure we have a valid control handle
  ; ***** oops user pressed Delete key and we get pre-empted
  ; ***** user removed the selected control.
  ; ***** Returning from the RemoveSelectedControl function and resuming here:
        GuiCtrlSetPos($InfoAboutControls[$HandleForCurrentControl], $newLeftPosition, $newTopPosition)
    EndIf
WEnd

Func RemoveSelectedControl()
    $HandleForCurrentControl = -1
EndFunc

2. If-check inside interrupt function

Hotkey only.

Flag is set right after if check.

It's possible or not this function print twice or more?

HotKeySet("{Delete}", "_TestHotkey")

Func _TestHotkey()
  Static $bFlag = True
  If ($bFlag) Then 
     ; ***** Right here, user pressed Delete key
     ; ***** bFlag is currently not set
     ; ***** And the script will execute this function twice or more times, instead of just once
     $bFlag = False
     ConsoleWrite("This should be printed only ONCE")
  EndIf
EndFunc

3. Same as 2, but with global flag

The question is: can I rely on if-checking with a flag, to ensure that my script doesn't do any strange things, as describe in the above examples?

Edited by binhnx

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Share this post


Link to post
Share on other sites



Not a specific script. That is only a general problem, and I ask for a general answer.

Indeed, 3 above examples is details as much as it should. Any line added to that is for nothing but make the topic unfocused.

To provide more details, 

  • Details about example 1 can be read in the original topic linked.
  • For example 2 and 3: As you see, my script only allow _TestHotkey() function to execute exactly once. But since AutoIt script can be interrupted and reentrant, it's probably that function be executed twice or more, if user presses "Delete" key right after the if-check line is executed. So, I need an assurance that AutoIt "had some mechanism" to play with it, like a Critical Section as describe at the linked topic.

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Share this post


Link to post
Share on other sites

There is almost no possibility of that function running twice if you clear the hotkey/adlib function used to call it as the very first line of the function.

HotKeySet("{Delete}", "_TestHotkey")

Func _TestHotkey()
  HotKeySet("{Delete}")
  Static $bFlag = True
  If ($bFlag) Then 
     ; ***** Right here, user pressed Delete key
     ; ***** bFlag is currently not set
     ; ***** And the script will execute this function twice or more times, instead of just once
     $bFlag = False
     ConsoleWrite("This should be printed only ONCE")
  EndIf
EndFunc

If you wanted the HotKey to be active again, you'd need to set it again somewhere else in the script. AdlibUnRegister would work the same way.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Or:

$bFlag = True
HotKeySet("{Delete}", "_TestHotkey")

Func _TestHotkey()
  If $bFlag Then 
     ; ***** Right here, user pressed Delete key
     ; ***** bFlag is currently not set
     ; ***** And the script will execute this function twice or more times, instead of just once
     $bFlag = False
     ConsoleWrite("This should be printed only ONCE")
  EndIf
EndFunc

While True
WEnd
Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

@BrewmanNH: yeah, in your case, if Delete is pressed right at the function begining, before the HotKeySet line, so what will happen?

In general, it also very very low probability, but i need to an exactly zero. 

Indeed, with Hotkey, if a line is the smallest element in AutoIt, so interrupt a line never can occur, so another trick will be better:

Func _TestHotKey()
 Static $nCounter = 0
 $nCounter += 1
 If ($nCounter = 1) Then
  ;Do everything you want
 EndIf
 $nCounter -= 1
EndFunc

It guarantee that the function execute exactly once (at the same time). But this method cannot be used with event or adlib since all that is queued, not interruped & reentrant.

@jdelaney: It's exactly my example 3. It's still unsafe at all, unless a dev state that it's safe!

A side note: The set flag statement is right after the check statement. I wonder AutoIt has some guard around it, or it's still simply a race-condition problem.

Edited by binhnx

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Share this post


Link to post
Share on other sites

There's probably a .000000000000000000000000001% chance that someone could hit the same key twice in the time it takes to get to that line. There's no such thing as exactly zero in computers, you are NEVER going to achieve that, especially in an interpreted language.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

@BrewmanNH.

No, as seen in the linked topic: '?do=embed' frameborder='0' data-embedContent>>

If a Critical Section (or any other guards) is implemented, it should be exactly zero!

The linked topic is provide a little information so I do not know it is implemented or not, so I open this topic to ask.

A side note: Computing is all about zero and one, isn't it?


99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Share this post


Link to post
Share on other sites

We're talking about timing, not numbers. Also, if you had read the first response to that nearly 10 year old thread, the answer given is exactly what I proposed.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Yeah, just kidding :)

I've read, and notice that, but after search along the forum, no other topic describe that problem, so I haven't know about its state yet.

In computing, many method is implemented to ensure that everything is done right. In a general programming language, also count interpreted language, such as Python or PHP also implemented that, using a lock before the check and the problem solved.

Is AutoIt (internally) did that?

Edit: Maybe I mis-understood what the Overlord said? Did he said that the guard function is totally imlemented? Or totally ignored? Or he said that the guard function is implemented around the disable Hotkey/Adlib/OnEvent function? 

Edited by binhnx

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Share this post


Link to post
Share on other sites

There is no guard function, you'd have to program that yourself, and it's all about disabling the hotkey or adlib as soon as you enter the function. Either by calling another function to clear it, or by implementing it inside the function being called. You're worrying over less than nothing in this thread, the function won't be called twice because you can't press the hotkey that fast, it's as close to zero time as is possible on a computer and using an interpreted language. If you need something quicker than almost instantaneous, you need to use another language.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Thank you for your patience, but it seems not much logic since the OP of the linked topic can disable Adlib/Hotkey/OnEvent right before check statement and re-enable it after go out of work section, without using CriticalSection guard, but still ensure script works right.

And, with the behavior of AutoIt when processing Event/HotKey/Adlib, using CriticalSection inside a script is a bad idea, because it:

  • Have no effect when using inside Event/Adlib function, since these kind result in a queued function call, so next EnterCriticalSection always called after last LeaveCriticalSection is called => no effect at all
  • Resulted in dead-lock when using with Hotkey, think about Hotkey is pressed right after called to EnterCriticalSection, and it resulted in wait for a not-released CriticalSection, also, to release it, the function should be returned from the later Hotkey function, but it's stuck since the later one is stuck in EnterCriticalSection call. Using multipleCriticalSection (using local variable so we have one with each called function) is out of concept because it cannot guarantee anything if we use it like that.
  • Use inside a normal function/mail script: has not much logic, since a normal disable function will solve the problem.

Furthermore, writing using a different language is not an option. You may think I mad, it's OK. Maybe I somewhat like AutoIt and I want to write in AutoIt than using a different language.

But this time, the reason makes me stick with AutoIt is I'm writing a program that use AutoIt as underlying rendering program (Yes, a form designer, AutoIt lacks a good designer. First, I need a native renderer, instead of using another language to do it, as Koda used Delphi. This will provide a better experiencement to user, since the designer form is exactly visually identified with the result form. Second, The FormBuilder Beta found in the forum - which is written entirely in AutoIt - is elegance, but too much crashable bug. So I decided to write a new one)

Edited by binhnx

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Share this post


Link to post
Share on other sites

 

And, with the behavior of AutoIt when processing Event/HotKey/Adlib, using CriticalSection inside a script is a bad idea, because it:

How do you know that? Have you ever run into a problem with using what I posted? Not some theoretical "what-if" scenario, I mean real world examples of where a hotkey can be pressed quicker than it takes to disable it in the function that's called by it. Have you ever encountered a deadlock condition from using a hotkey in the way I demonstrated? My guess would be no to all questions, because the probability of it happening is extremely small.

If you think you can show a way to do it, please post a script that demonstrates it.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Have you ever seen any real-world-100%-will-occur-race-condition?

The answer is 'absolutely NO', because this is very very rare to occur, but every one can ensure that, at a random (not-so) beautiful day, your application will crash stupidly because a stupid bug. It's not acceptable with a programmer, but may be acceptable with a scripter/ automater. 

It's not speed problem. It's timing problem.

It's not about how many small. It's YES or NO


99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Share this post


Link to post
Share on other sites

Maybe I asked at wrong forum region.

Anyone may have a look at 

and give me some advice? Thank you very much!


99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Share this post


Link to post
Share on other sites

You have a thread going, which is getting replies (even if not fast enough for you). Please don't double post


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

I think, I posted in the wrong thread. all I need is a answer by a developer, who can easily say that yes or no. I'm tired of explaining anything about my question.

Should I delete the thread and re-post?

Edited by binhnx

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Share this post


Link to post
Share on other sites

Not if you want a long and healthy stay on the forum :)

If people are still asking for clarification, maybe you should take that as a clue that you're not explaining yourself very well.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

So, honestly, may you spend some time to read my post and give me some point, what do I need to answer, to get the answer for me?

Edited by binhnx

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning guys
      I was trying to not open another post, writing here my little issue, but seems that no one cares about, and so, I'm opening another post
      What I'm trying to do, is detect the event close sent from the virtual keyboard.
      Why?
      Because, I have an application which, when I set the focus on a textbox, if the virtual keyboard does not exist, then it is created, else, it's not created
      But, everytime I try to close the virtual keyboard, the focus remains on the textbox, and another $EN_FOCUS event it's launched and detected from my WM_COMMAND, and so, the virtual keyboard is opened again. 
      How can I solve this little "issue"? 
      I was trying to detect the event sent from the virtual keyboard, storing the handle of it in a variable, and setting:
      GUISetOnEvent($GUI_EVENT_CLOSE, "CloseVK", $hVirtualKeyboard) without any result.
      Can someone please help me?
      Thanks  
      EDIT:
      Here I'd like to see @Melba23, @water, @Danyfirex...
       
    • Xandy
      By Xandy
      Screenshot program that can upload/FTP to website/storage with hotkey.
      Features GUI to display programmable keys.

      Set the hotkeys with this function to use, and display hotkeys.
      ; hotkey_set() Parameters: ; ----------------------------------------------------------- ; $aHotkey -                The array hotkeys are stored in. This function sets the values of this array[hotkey_id][$hotkey_data] ; $dHotkey_id -             The enum for this hotkey index ; $sHotkey_description -     The label displayed to the user to represent function of hotkey ; $sHotkey_name -            The hotkey it'self.  Whatever name string you want to give the key ; $dHotkey_key -             The _IsPressed keycode ;    Keycodes AT: https://www.autoitscript.com/autoit3/docs/libfunctions/_IsPressed.htm ; $dHotkey_shift -             Shift flag 0 or 1 Default off ; $dHotkey_ctrl -             Ctrl flag 0 or 1 Default off ; $dHotkey_alt -             Alt flag 0 or 1 Default off Func hotkey_set(ByRef $aHotkey, $dHotkey_id, $sHotkey_description, $sHotkey_name, $dHotkey_key, $dHotkey_shift = 0, $dHotkey_ctrl = 0, $dHotkey_alt = 0)     $aHotkey[$dHotkey_id][$eHotkey_data_key_description] = $sHotkey_description     $aHotkey[$dHotkey_id][$eHotkey_data_key_name] = $sHotkey_name     $aHotkey[$dHotkey_id][$eHotkey_data_key] = $dHotkey_key     $aHotkey[$dHotkey_id][$eHotkey_data_shift] = $dHotkey_shift     $aHotkey[$dHotkey_id][$eHotkey_data_ctrl] = $dHotkey_ctrl     $aHotkey[$dHotkey_id][$eHotkey_data_alt] = $dHotkey_alt EndFunc   ;==>hotkey_set ; You can set your hotkeys here ; Please visit the hotkey_set() function for parameter information hotkey_set($aHotkey, $eHotkey_screenshot_ftp, "Selected Window to FTP", "F12", "7B", 0, 1, 0); F12 hotkey_set($aHotkey, $eHotkey_screenshot_disk, "Selected Window to Disk", "S", "53", 1, 1, 1); S hotkey_set($aHotkey, $eHotkey_clipboard_send, "Send Clipboard keystrokes", "F10", "79", 1, 1, 1); F10  
      Configure settings dialog:

      Screenshot Filename and Screenshot Counter, are used to create simple unique filenames that can cycle. Copy URL to clipboard option. - For linking your screenshots. The screenshot file type is for local copy only. App always uses .JPG for FTP right now, but I could add FTP screenshot file type specification.  
      Any suggestions?  Did I break anything, what did I miss?
      Package uses TTS.au3 by Beege: 
       
      FTP_Screen.zip
      File includes:
         - FTP_Screen.au3
         - FTPScreen.ico
         - TTS.au3 - by Beege
    • vindicta
      By vindicta
      Hello everyone,
      I am trying to setup a GUI accelerator to close the utility as soon as esc is pressed.  It works fine with hotkey but I want to make sure that the utility only exits if its window was active when esc was pressed. My utility has 2 buttons, Backup and Restore.
      The exit function checks if the button clicked was Backup or Restore and then displays an error message accordingly.
      If pressed backup, $button = 1
      if pressed restore, $button = 2
      the value of $button is set inside backup() or restore() functions
      Opt("GUIOnEventMode", 1) Opt("GUICoordMode", 1) $Form1 = GUICreate("Form1", 419, 124, 238, 194, $WS_DLGFRAME) $B_backup = GUICtrlCreateButton("Backup", 48, 40, 145, 41) $B_restore = GUICtrlCreateButton("Restore", 224, 40, 145, 41) ;================ > HotKeySet('{ESC}', "terminate") GUICtrlSetOnEvent($B_backup, "Backup") GUICtrlSetOnEvent($B_restore, "Restore") GUISetState(@SW_SHOW) Dim $accelKey[1][2] = [["{ESC}", terminate()]] GUISetAccelerators($accelKey) While 1     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             Exit     EndSwitch WEnd  
      Exit function:
      func terminate() Do     $msg = GUIGetMsg() Until $msg <> 0 While 1         If $button = 1 Then             ProcessClose("robocopy.exe")             MsgBox(16, "Abort!", "Backup Aborted!")             exit         ElseIf $button = 2 Then             ProcessClose("robocopy.exe")             MsgBox(16, "Abort!", "Restore Aborted!")             exit         Else             While 1                 For $i = 3 To 1 Step -1                     SplashTextOn("Closing Utility...", $i, 130, 54, -1, -1, 0, "Calibri", "", 900)                     Sleep(1000)                 Next                 ExitLoop             WEnd             SplashOff()             Exit Endif WEnd What am I doing wrong here? The utility closes as soon as it launches with Splash text.
    • jonson1986
      By jonson1986
      Hello,
      I've thousands of URLs to check them these are safe, malware infected or any other type of error, that's why I searched and found Google Safe browsing API with this we can send HTTP GET request so different code will return to make us clear is it our sent URL is safe or not. Please guide me how can i make this possible I know basics of Auotit but don't know how to use this API to fulfill above mentioned purpose. Your help will be much appreciated. Thanks
      Here is API URL;
      https://developers.google.com/safe-browsing/v3/lookup-guide
    • ruslanas402
      By ruslanas402
      Hello AutoIt fans, could anyone help  me to get back on track please? So I managed to interrupt  my function by pressing "Func two" button. But how can I terminate fuction by pressing "X" in GUI ? How can I assign "X" button to "Func two" if that's possible.
      Regards
      Ruslanas402
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $fInterrupt = 0 $hGUI = GUICreate("Test", 500, 500) $hButton_1 = GUICtrlCreateButton("Func One", 10, 10, 80, 30) $hButton_2 = GUICtrlCreateButton("Func Two", 10, 50, 80, 30) GUISetState() GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) If BitAND($wParam, 0x0000FFFF) = $hButton_2 Then $fInterrupt = 1 Return $GUI_RUNDEFMSG EndFunc While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton_1 _Func_1() Case $hButton_2 Exit EndSwitch WEnd Func _Func_1() $fInterrupt = 0 For $i = 1 To 10 ConsoleWrite("-Func 1 Running" & @CRLF) If _Interrupt_Sleep(5000) Then Switch $fInterrupt Case 1 ConsoleWrite("!Func 1 interrrupted" & @CRLF) EndSwitch Return EndIf Next ConsoleWrite(">Func 1 Ended" & @CRLF) EndFunc Func _Interrupt_Sleep($iDelay) Local $iBegin = TimerInit() Do Sleep(10) If $fInterrupt Then Return True EndIf Until TimerDiff($iBegin) > $iDelay Return False EndFunc