Sign in to follow this  
Followers 0
hooked

Find out running function

7 posts in this topic

#1 ·  Posted (edited)

Is there any way to find out if another user function is running before queuing another one? For example, I have a GUI with 2 buttons, button one runs and waits for an external program (that can take from 1 second up to 5 minutes), and button 2 does something else. The problem is that while Func1 is running, Func2 can be called multiple times and run more often than it should, creating problems. I made some code up below to try to show the problem. I have tried searching but cant find anything... what i want is if func1 is running when Button 2 is pressed, it comes up with a message box "Please wait, program is busy" or something, rather than queuing Func2 to run when Func1 is finished

Opt("GUIONEVENTMODE", 1)
GUICreate("", 200, 200)
GUICtrlCreateButton("Button 1", 0, 0, 200, 100)
GUICtrlSetOnEvent(-1, "_Func1")
GUICtrlCreateButton("Button 2", 0, 100, 200, 100)
GUICtrlSetOnEvent(-1, "_Func2")
GUISetState()
while 1
    Sleep(100)
WEnd
Func _Func1()
    $returncode =  runwait("program.exe")
EndFunc
Func _Func2()
    MsgBox(0, '', 'Func2 Called')
EndFunc
Edited by hooked

Share this post


Link to post
Share on other sites



Have you tried

ProcessExists("program.exe")

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

yes, the problem is the script is doing a runwait not run (to get the return code), so the script is hanging on that line. so by the time Func2 runs , the program is always finished, however it then tries to call Func2 as many times as the button was pressed...

Share this post


Link to post
Share on other sites

How about disabling the buttons while the program in Func 1 is running? Then the user cannot, and knows not, to do a bunch of clicking around while waiting. Just enable them again after the program finishes.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Yes thats an option, i was hoping there would be an alternative though, as being able to queue the functions is a good thing, but i want to be able to handle it better so i dont get the same function running multiple times. For example, its ok to press button 2 so func2 runs directly after func1, but i dont want func2 running 20 times if button 2 pressed 20 times.

There may already be a solution out there but im not using the right terminology - you need something like _GetQueuedAutoITFunctions() which would return an array of all functions that are waiting to run.

Edited by hooked

Share this post


Link to post
Share on other sites

Yes thats an option, i was hoping there would be an alternative though, as being able to queue the functions is a good thing, but i want to be able to handle it better so i dont get the same function running multiple times. For example, its ok to press button 2 so func2 runs directly after func1, but i dont want func2 running 20 times if button 2 pressed 20 times.

There may already be a solution out there but im not using the right terminology - you need something like _GetQueuedAutoITFunctions() which would return an array of all functions that are waiting to run.

If you want to just keep _Func2 from running 20 times because you got antsy, how about something like this?

Opt("GUIONEVENTMODE", 1)

$vFunc2Ran = 0

GUICreate("", 200, 200)
GUISetOnEvent ($GUI_EVENT_CLOSE, "_GUI_EVENT_CLOSE")
GUICtrlCreateButton("Button 1", 0, 0, 200, 100)
GUICtrlSetOnEvent(-1, "_Func1")
GUICtrlCreateButton("Button 2", 0, 100, 200, 100)
GUICtrlSetOnEvent(-1, "_Func2")
GUISetState()

while 1
    Sleep(100)
WEnd
Func _Func1()
    $returncode =  runwait("program.exe")
EndFunc
Func _Func2()
    If $vFunc2Ran = 0 Then
        $vFunc2Ran = 1
        MsgBox(0, '', 'Func2 Called')
    EndIf
EndFunc
Func _GUI_EVENT_CLOSE()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

getting there! tweaked that concept a bit, see below. it works, but sometimes functions are called with parameters... anyone got any ideas?

Opt("GUIONEVENTMODE", 1)
#include <GUIConstantsEx.au3>

global $RunFunc1 = 0, $RunFunc2 = 0

GUICreate("", 200, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "_GUI_EVENT_CLOSE")
GUICtrlCreateButton("Button 1", 0, 0, 200, 100)
GUICtrlSetOnEvent(-1, "_Func1_Caller")
GUICtrlCreateButton("Button 2", 0, 100, 200, 100)
GUICtrlSetOnEvent(-1, "_Func2_Caller")
GUISetState()

While 1
    Sleep(100)
    If $RunFunc1 = 1 Then _Func1()
    If $RunFunc2 = 1 then _Func2()
WEnd

Func _Func1_Caller()
    $RunFunc1 = 1
EndFunc   ;==>_Func1_Caller
Func _Func2_Caller()
    $RunFunc2 = 1
EndFunc   ;==>_Func2_Caller

Func _Func1()
    $returncode = RunWait("program.exe")
    MsgBox(0, '', 'Program Finished Running...')
    $RunFunc1 = 0
EndFunc   ;==>_Func1
Func _Func2()
    MsgBox(0, '', 'Func2 Called')
    $RunFunc2 = 0
EndFunc   ;==>_Func2

Func _GUI_EVENT_CLOSE()
    Exit
EndFunc   ;==>_GUI_EVENT_CLOSE

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