Sign in to follow this  
Followers 0
sonofalion

GUI unresponsive while internal function runs

12 posts in this topic

So,, I got a GUI with some buttons on it.

When you press button "A", an internal function is executed and you have to wait for it to end in order to be able to press button "B". How can this be overcome?

I have tried both MessageLoop and OnEvent Modes.

I'm sure this is a very basic question that requires a very basic answer. Thanks to anybody that cares to help.

Paris

Share this post


Link to post
Share on other sites



In your internal function invoked from button A (I expect some type of loop) add this:

If GUIGetMsg() = $button_b Then Func_B()
Right. But wouldn't it wait for function "B" then to end in order to continue with the loop in function "A"?

Also, isn't this impractical for a large amount of buttons/functions?

Share this post


Link to post
Share on other sites

Right. But wouldn't it wait for function "B" then to end in order to continue with the loop in function "A"?

Also, isn't this impractical for a large amount of buttons/functions?

AutoIt, as far as I know, can't do two or more things at the same time.

One way, maybe the only one, to do things parallel is to start a new autoit script, or several.

If that's what you want.


You can fool some of the people all of the time, and all of the people some of the time, but you can not fool all of the people all of the time. Abraham Lincoln - http://www.ae911truth.org/ - http://www.freedocumentaries.org/

Share this post


Link to post
Share on other sites

Right. But wouldn't it wait for function "B" then to end in order to continue with the loop in function "A"?

Also, isn't this impractical for a large amount of buttons/functions?

Just make some helper function for example CheckGui() and call it from places where you need to react for GUI events.

In this function will be $msg = GUIGetMsg() and whole message Case statement.

Share this post


Link to post
Share on other sites

Just make some helper function for example CheckGui() and call it from places where you need to react for GUI events.

In this function will be $msg = GUIGetMsg() and whole message Case statement.

There is another possibility but it depends on your application so it might not suit.

You use OnEvent mode. Then the problem is that when you press button A and a function is called, then if you press Button B it won't respond to button B until it exits the function. This is because Events are queued. If however you call a function from your main idle loop then an event can interrupt the function. So instead of the function being long just set a flag. When you see the flag in your main loop call the real function. Then when you press Button B you get an immediate response.

GuiCtrlSetOnEvent($BtnA,"FuncA")
GuiCtrlSetOnEvent($BtnB,"FuncB")

$CallA = false

While 1
sleep(50)
 If $CallA then
  FuncC();your long function
 $CallA = false
endif
wend

Func FuncA(); $BtnB cannot interrupt this
 $CallA = true;but it's so short who cares
endfunc

Func FuncB()
;something
EndFunc

Func FuncC(); BtnB can interruot this
;lots of code here
endfunc

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

There is another possibility but it depends on your application so it might not suit.

You use OnEvent mode. Then the problem is that when you press button A and a function is called, then if you press Button B it won't respond to button B until it exits the function. This is because Events are queued. If however you call a function from your main idle loop then an event can interrupt the function. So instead of the function being long just set a flag. When you see the flag in your main loop call the real function. Then when you press Button B you get an immediate response.

GuiCtrlSetOnEvent($BtnA,"FuncA")
GuiCtrlSetOnEvent($BtnB,"FuncB")

$CallA = false

While 1
sleep(50)
 If $CallA then
  FuncC();your long function
 $CallA = false
endif
wend

Func FuncA(); $BtnB cannot interrupt this
 $CallA = true;but it's so short who cares
endfunc

Func FuncB()
;something
EndFunc

Func FuncC(); BtnB can interruot this
;lots of code here
endfunc

But A still stops, doesn't it? I think immediate reaction was also possible with Zedna's tipp in post #2.

I understood it that he needs both functions at the very same time (see post #3). (??)


You can fool some of the people all of the time, and all of the people some of the time, but you can not fool all of the people all of the time. Abraham Lincoln - http://www.ae911truth.org/ - http://www.freedocumentaries.org/

Share this post


Link to post
Share on other sites

_coproc or any other type of ""multithreading"" is what he is looking for, i think....


[u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?!

Share this post


Link to post
Share on other sites

I understood it that he needs both functions at the very same time (see post #3). (??)

Ah yes. Then I think more than one script is needed.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Ah yes. Then I think more than one script is needed.

Guys, thanks for your feedback. I am not looking for multithreading or anything, just a way to run two functions at the same time, which are triggered by two different buttons on the GUI, available all the time.

I will check the solutions given here and let you know.

Paris

Share this post


Link to post
Share on other sites

Well, actually that is multithreading. AutoIt is single threaded and can only do one thing at a time. Running 2 functions concurrently is.... two things :P

Share this post


Link to post
Share on other sites

Well, actually that is multithreading. AutoIt is single threaded and can only do one thing at a time. Running 2 functions concurrently is.... two things :P

Riiight, I hadn't realized that. Got it!

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