Click here to Skip to main content
15,893,968 members
Home / Discussions / C#
   

C#

 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 10:51
Jacob Dixon12-Apr-10 10:51 
GeneralRe: Stopping threads (semi-safely).... Pin
PIEBALDconsult12-Apr-10 13:02
mvePIEBALDconsult12-Apr-10 13:02 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 13:39
Jacob Dixon12-Apr-10 13:39 
GeneralRe: Stopping threads (semi-safely).... Pin
PIEBALDconsult12-Apr-10 13:51
mvePIEBALDconsult12-Apr-10 13:51 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 13:58
Jacob Dixon12-Apr-10 13:58 
GeneralRe: Stopping threads (semi-safely).... Pin
PIEBALDconsult12-Apr-10 14:15
mvePIEBALDconsult12-Apr-10 14:15 
GeneralRe: Stopping threads (semi-safely).... Pin
Dave Kreskowiak12-Apr-10 15:33
mveDave Kreskowiak12-Apr-10 15:33 
AnswerRe: Stopping threads (semi-safely).... Pin
William Winner12-Apr-10 10:23
William Winner12-Apr-10 10:23 
I agree with Dave. You should set up a class to do the work for you, and when it is complete, it should fire an event that returns the values it found.

As an example, I have a program that has to extract the column information from an OLAP data cube. This process can take a long time, but I need the information to fill out the different parts of the form. But, sometimes, the user has finished filling out the form before the entire cube was loaded, or they decide to quit. So, on the form close, the first thing I do is to hide the form. As far as the user is concerned, the form is hidden.

Then, I send the call to the class to tell it to abort. The class looks for that abort message periodically as its working, and if it gets it, it will quit loading. Then, in the Form_Close method, I hook the BackgroundWorker.RunWorkerCompleted Event. When that event fires, I know that the process has completed, and I can dispose of the thread and form safely.

In your case, you can't tell it to prematurely stop, but you can let it finish loading in the background, but still hide the form from the user so that they think it is closed.
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 10:27
Jacob Dixon12-Apr-10 10:27 
GeneralRe: Stopping threads (semi-safely).... Pin
Luc Pattyn12-Apr-10 10:55
sitebuilderLuc Pattyn12-Apr-10 10:55 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 11:14
Jacob Dixon12-Apr-10 11:14 
GeneralRe: Stopping threads (semi-safely).... Pin
Luc Pattyn12-Apr-10 11:23
sitebuilderLuc Pattyn12-Apr-10 11:23 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 11:27
Jacob Dixon12-Apr-10 11:27 
GeneralRe: Stopping threads (semi-safely).... Pin
Luc Pattyn12-Apr-10 11:40
sitebuilderLuc Pattyn12-Apr-10 11:40 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 11:23
Jacob Dixon12-Apr-10 11:23 
GeneralRe: Stopping threads (semi-safely).... Pin
William Winner12-Apr-10 11:01
William Winner12-Apr-10 11:01 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 11:07
Jacob Dixon12-Apr-10 11:07 
GeneralRe: Stopping threads (semi-safely).... Pin
William Winner12-Apr-10 12:49
William Winner12-Apr-10 12:49 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 13:40
Jacob Dixon12-Apr-10 13:40 
AnswerRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 14:38
Jacob Dixon12-Apr-10 14:38 
GeneralRe: Stopping threads (semi-safely).... Pin
DaveyM6912-Apr-10 14:46
professionalDaveyM6912-Apr-10 14:46 
AnswerRe: Stopping threads (semi-safely).... Pin
DaveyM6912-Apr-10 14:44
professionalDaveyM6912-Apr-10 14:44 
QuestionMultithreaded drawing Pin
Groulien12-Apr-10 9:07
Groulien12-Apr-10 9:07 
AnswerRe: Multithreaded drawing Pin
Tarakeshwar Reddy12-Apr-10 9:37
professionalTarakeshwar Reddy12-Apr-10 9:37 
AnswerRe: Multithreaded drawing Pin
ntrceptr12-Apr-10 9:46
ntrceptr12-Apr-10 9:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.