Page 1 of 1

Handling dialog and pop up windows example

Posted: Thu Apr 29, 2010 4:26 pm
by tamiro
I'm having a hard time figuring out how to close the pop-up thread. I just want to leave it in the While loop watching for pop-ups until the main program finishes. When the main program returns the console window is left up. When I don't start the thread for clicking off pop-ups, when the test finishes the console goes away, so I'm pretty sure that the pop-up thread is somehow causing the console to say up, and that I should be closing the thread by breaking out of the While loop somehow.

BTW, I loved your blog and sample on handling dialog and pop up windows. I just need to get it working without a hitch.

Tom

Re: Handling dialog and pop up windows example

Posted: Thu Apr 29, 2010 4:47 pm
by Ciege
What is your code for the worker thread you are using and how are you starting / stopping it?

I start my worker thread from the beginning of my main thread before testing begins. Then, when the main thread has completed its testing I call workerThread.Abort(); as the last step to stop my worker thread.

Start from main thread:

Code: Select all

// Create the thread object. This does not start the thread.
Worker workerObject = new Worker();
workerObject.MainThread = Thread.CurrentThread;
Thread workerThread = new Thread(workerObject.ThreadTask);

// Start the worker thread.
workerThread.SetApartmentState(ApartmentState.STA);
workerThread.IsBackground = true;
workerThread.Start();
End from main thread:

Code: Select all

workerThread.Abort();

Re: Handling dialog and pop up windows example

Posted: Thu Apr 29, 2010 4:53 pm
by Support Team
You can also set the IsBackground property of your worker thread to true. That way, the process is not blocked from terminating even if the worker thread still runs. See the MSDN documentation of that property for more info:
http://msdn.microsoft.com/en-us/library ... round.aspx

Regards,
Alex
Ranorex Support Team

Re: Handling dialog and pop up windows example

Posted: Fri Apr 30, 2010 3:45 pm
by tamiro
Thanks. Both methods worked. I could have sworn that I tried using Abort and saw something about it being obsolete. I must have been confused. I like the background property, so this is what my code has now.

dialogWatcher = new Thread(ClosePopUpDialogs);
dialogWatcher.SetApartmentState(ApartmentState.STA);
dialogWatcher.IsBackground = true;
dialogWatcher.Start();