Jump to content
Sign in to follow this  

Interrupting a Running Function

Recommended Posts

I have a bit of an interesting situation, and I am wondering if there is a way to resolve my problem.

While 1   
   Switch GUIGetMsg()
      Case $exitbutton
      Case $startbutton
      Case $stopbutton
      Case $clearbutton

Func Run_Setup()
     If GuiCtrlRead($Box1)=1 Then Function1()
     If GuiCtrlRead($Box2)=1 Then Function2()
     If GuiCtrlRead($Box3)=1 Then Function3()

Where Function1, Function2, Function3 are just a bunch of GUI commands.

Sometimes within those functions something will go wrong (i.e. a WinWaitActive command may be incorrect).

This causes the program to get stuck at that point, and I have to right click on the task bar and terminate the function (because the GUI doesnt have control).

I want to add a "STOP" button to my gui that will terminate whatever is running and just restore my GUI to the original state.

Is there a way to do that?

Note: I have read http://www.autoitscript.com/wiki/Interrupting_a_running_function and it seems that will only be useful when my main function is in a loop and checking on each iteration the value of $fInterrupt...

Any other suggestions?

Share this post

Link to post
Share on other sites

Hi, jedd999. You state your functions are "just a bunch of GUI commands". What kind of commands, and what error checking are you doing? For example, if you're using a call to GUICtrlSetData, to enter data - are you then doing a check to ensure this happened? If I am missing what you're trying to do, perhaps some code showing some of the commands in your function would help.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Share this post

Link to post
Share on other sites

The way that you are trying to solve this issue doesn't appear to be the most direct.

Most blocking AutoIt functions have a timeout parameter or an alternative, non-blocking, way of achieving the same results. What you appear to need, is more knowledge about how these methods work and what the difference between non-blocking and blocking methods are.

Take WinWaitActive, for example. It has a third, and optional, parameter that defines the "timeout". The timeout is the length of time in which the function will wait for a result, after this time has passed the function will then return, maybe even empty handed.

If you use this timeout parameter, then the method will return regardless of success, allowing the smooth operation of your script. Given that WinWaitActive is your issue, of course.

Ultimately, I don't believe you're going to find a standard method for interrupting a native AutoIt function, while its in the middle of something.

Share this post

Link to post
Share on other sites

I managed to resolve the problem by setting an interrupt (that was attached to a button) and just exiting the script with an adlib function if the button is pressed (at any time)

Not an elegant solution, but it works...

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...