tags:

views:

55

answers:

3

I want to use it for a project and I am in trouble. I have a Windows Form in which I started two threads and then close the form and threads continue their works. How can I abort first thread when the second thread stops?

I made the first thread IsBackground,but the second thread is not the only thread of program and the first thread is started in another thread(form) that is closed and not exists anymore,in addition I can't set Flag of a Class that doesn't exist. What should I do?

for solving this problem i want your email to send my litle project. Thanks

A: 

You say that you can set a flag or class that doesn't exist, but I'd create a flag somewhere. If that's not possible I'd suggest that you need to post the reason for that.

So I'd send in a reference to a bool in some way to both threads, when the 1st thread finishes it would set the bool to true and the 2nd thread would keep checking this bool and then exit when it's true.

ho1
I am working with VB.NET2008 and i created a module and declare my threads and flag in it.If I have your email, I send my little project for you.Thank and sorry for my bad english.
Sadjad
+1  A: 

I recommend making the background work a Task object if you're on .NET 4.0, and use a CancellationToken to cancel the operation.

If you're not on .NET 4.0 yet, you can use the BackgroundWorker object which also supports cancellation.

Stephen Cleary
A: 

You're probably better off not creating the thread from a form which is going to disappear. Perhaps you should create the threads in Program.cs and then you can kill them from there as well when the application closes. Or some variant of this method depending on how your application is structured.

Vincent McNabb
I am working with VB.NET2008 and i created a module and declare my threads and flag in it.If I have your email, I send my little project for you.Thank and sorry for my bad english.
Sadjad