Handling dialog and pop up windows example

Ask general questions here.
tamiro
Posts: 10
Joined: Fri Apr 16, 2010 3:31 pm

Handling dialog and pop up windows example

Post by tamiro » Thu Apr 29, 2010 4:26 pm

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

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Handling dialog and pop up windows example

Post by Ciege » Thu Apr 29, 2010 4:47 pm

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();
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Handling dialog and pop up windows example

Post by Support Team » Thu Apr 29, 2010 4:53 pm

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

tamiro
Posts: 10
Joined: Fri Apr 16, 2010 3:31 pm

Re: Handling dialog and pop up windows example

Post by tamiro » Fri Apr 30, 2010 3:45 pm

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();