无法杀死在Silverlight中工作线程线程、工作、Silverlight

由网友(烟花巷陌)分享简介:我工作的一个多线程的Silverlight应用程序。I'm working on a multi-threaded Silverlight application.应用程序有两个线程:主/用​​户界面和后台工作线程The application has two threads: Main/UI and a bac...

我工作的一个多线程的Silverlight应用程序。

I'm working on a multi-threaded Silverlight application.

应用程序有两个线程:主/用​​户界面和后台工作线程

The application has two threads: Main/UI and a background working thread.

在UI线程应该能够杀死后台线程,就像这样:

The UI thread should be able to kill the background thread, like so:

private Thread executionThread;

....

executionThread = new Thread(ExecuteStart);
executionThread.Start();

....

executionThread.Abort(); // when the user clicks "Stop"

最后一行抛出一个异常:

The last line raises an Exception:

MethodAccessException:尝试访问该方法失败:System.Threading.Thread.Abort()

MethodAccessException: Attempt to access the method failed: System.Threading.Thread.Abort()

你知道吗?为什么我不能中止线程在Silverlight?

Any idea? why i cannot abort a thread in Silverlight?

谢谢, 纳伊米

推荐答案

而不是为了这个目的手动创建一个线程,你可能要考虑使用的 BackgroundWorker的类。

Rather than creating a Thread manually for this purpose you might want to consider using the BackgroundWorker class.

本类具有内置的功能来取消异步操作时WorkerSupportsCancellation =真。

This class has built in functionality for cancelling the asynchronous operation when WorkerSupportsCancellation = true.

有一个看看这篇文章在MSDN上的全如何使用BackgroundWorker的在Silverlight例如。

Have a look at this article on MSDN for a full example of how to use the BackgroundWorker in Silverlight.

阅读全文

相关推荐

最新文章