|
-
Sep 20th, 2007, 02:02 PM
#1
Thread Starter
Junior Member
[2005] Is it possible for a thread to show a form?
I started a thread to open a network connection to a server. If there is an error opening the connection, I want the thread to show a form telling the user to check to see if the server is running, then I put the thread to sleep for five seconds and loop back and try again. When I tried this the form showed, but the label with the message on it is just a blank white box and if I hover the cursor over the form it shows as an hourglass. So I'm wondering if it is it possible to do this or can you only show forms on the UI thread?
-
Sep 20th, 2007, 02:09 PM
#2
Re: [2005] Is it possible for a thread to show a form?
A thread can certainly show a form. The reason it does what it does is because you are putting the thread to sleep. You are putting this new forms UI thread to sleep and thats gonna cause all event handling, painting and everything to just halt. You should invoke a method on the main thread and open up the form from there, that way you can pause the worker thread without negative effects.
-
Sep 20th, 2007, 02:49 PM
#3
Thread Starter
Junior Member
Re: [2005] Is it possible for a thread to show a form?
When the thread resumes, shouldn’t it finish displaying the form? The form never fully displays.
-
Sep 20th, 2007, 03:55 PM
#4
Re: [2005] Is it possible for a thread to show a form?
I dont know, perhaps it has a negative impact on the creation of the form to put the creation thread to sleep so soon.
-
Sep 21st, 2007, 08:43 PM
#5
Re: [2005] Is it possible for a thread to show a form?
How are you displaying this form? You should be calling ShowDialog and not sleeping the thread until AFTER that returns. That said, it's not such a good idea to display forms on background threads because they may be ignored indefinitely. Even if you call ShowDialog the form will prevent access to the background thread, not the UI thread, so the user could keep on using your main form and simply ignore the message. That's not good design. If you want to interact with the user you should do it on the UI thread. Either delegate and display the form on the UI as a modal dialogue or else use a balloon tip on a NotfifyIcon if you don't want the message to interfere with the user's work on the main form.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|