Live Chat Icon For mobile
Live Chat Icon

WinForms FAQ - Threading

Find answers for the most frequently asked questions
Expand All Collapse All

There are several possible reasons for this.

Invoking Abort on a suspended thread will have no effect until the thread is resumed. Once it is resumed, then the Abort will be carried out.

Also, when closing your application, you can make sure that the secondary threads are terminated by calling Join (myWorkerThread.Join) immediately after invoking Abort on the thread. For instance, this would be necessary if the thread is in the middle of an intensive operation, or even if it is simply sleeping.

Permalink

In most cases, this can be resolved by making the thread a background thread through it’s IsBackground property.

By default, managed threads are created as foreground threads, while unmanaged threads are created as background threads. When all of the foreground threads in an application have terminated, the CLR invokes Abort on the background threads that are still running.

Permalink

While the STAThread is required (as the documentation states) and pertinent only to applications that use COM interop, 1.0 version of the .Net framework has some bugs that makes it necessary for you to specify the STAThread attribute:

1) Ole Drag Drop will not work without STA. You can check this by turning on drag and drop in a form and try to run it.

2) Invoking a method in a type using Reflection will not work either.

These bugs have however been resolved in the 1.1 version of the framework (Everett). Which means you then do not have to specify this attribute for your main method.

Permalink

Share with

Couldn't find the FAQs you're looking for?

Please submit your question and answer.