grip003 Posted November 9, 2006 Posted November 9, 2006 I am using VS2003, and I am trying to open a form in a new thread. What I have done is started a new thread from the main one, and in that thread I create a new form. The new form is used to display some loading results from the main form, but when I show the new form I just get an hourglass and I can't press the cancel button. Here is the simple idea: Show the main form. Start a new thread in the main form for loading. In the new thread, create a 2nd form to display some loading results. While the 2nd form is shown, I want the ability to cancel the loading operation. Does this seem possible? Quote
Leaders snarfblam Posted November 9, 2006 Leaders Posted November 9, 2006 I believe that all GUI components must be run on the same thread. Windows sends messages only to the thread that is running the message pump and these messages are all dispatched on that thread. It might be possible to call Application.Start(someForm) on your second thread, but I'm not too sure that windows would allow an application to have two message pumps. Quote [sIGPIC]e[/sIGPIC]
tfowler Posted November 10, 2006 Posted November 10, 2006 The GUI should remain on a single thread. The loading process is what should be on the 2nd thread. You will have to create some events on the loading thread with event handlers in your GUI code that check for InvokeRequired and use Invoke to switch to the GUI thread to update the forms. Here is a thread describing how I was doing it in .NET 1.1. I know .NET 2.0 has a BackgroundWorkerThread, which might make things easier. http://www.xtremedotnettalk.com/showthread.php?t=94252&highlight=thread Todd Quote
grip003 Posted November 10, 2006 Author Posted November 10, 2006 Thanks tfowler, that is the way I have been doing this in the past, I was just trying to come up with a slick form that I could use in a general way to perform any loading I wanted to do. According to marble_eater, that is just not possible. Oh well, thanks anyway. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.