Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

  • Leaders
Posted
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.
[sIGPIC]e[/sIGPIC]
Posted

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

Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...