0

I am using multiple thread in wpf windows.

I am using this.Close() to close the window, and open another window using newWindow.Show().

Code:

// open new windows newWindow newWindow = new newWindow(); this.Close(); newWindow.Show(); // close window private void OnClosed(object sender, EventArgs e) { // stop some events d.StopEvents(); } 

It will takes long time to reach StopEvents.

If I use Environment.Exit(0); it will close the application, I don't want that.

Thanks.

3
  • Please be more clear about the question you are posing. Commented Oct 4, 2012 at 15:29
  • Have you considered keeping track of your threads in a List<Thread> and calling Abort on them? Commented Oct 4, 2012 at 15:41
  • 1
    You really don't want to be using Abort unless you have no other choice as without very careful usage you may as well consider the method to be called, PleaseCorruptMyApplicationStateRandomly Commented Oct 4, 2012 at 15:43

2 Answers 2

3

What are your threads doing? A common pattern is for working threads to periodically check a flag to see whether they need to close themselves. It's much safer for each thread to do that than for another tread to abort it.

Sign up to request clarification or add additional context in comments.

Comments

1

You might also want to consider using the Parallel extensions (TPL) as this makes threading much easier, and comes with concepts like Cancellation baked in.

.NET 4 Cancellation Framework

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.