我该如何解决这个错误 [英] How Could I Solved This Error

查看:128
本文介绍了我该如何解决这个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



线程正在运行或终止;它无法重新启动.

谢谢.



Thread is running or terminated; it cannot restart.

Thanks.

推荐答案

您无法重新启动线程,没有这样的概念(那很好).

您只创建一个新的线程对象,然后通过其他线程启动它.从那一刻起,不再需要对System.Threading.Thread.Start进行任何调用.您的问题是您正在尝试执行此操作,这没有任何意义.相反,您必须让该线程终止或中止它.如果仍然需要该线程,则可以使用与构造函数相同的委托实例或其他某个实例来创建另一个线程.

替代方法是使用线程池或 System.ComponentModel.BackgroundWorker:
http://msdn.microsoft.com/en-us/library/system.threading. threadpool.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/vstudio/system. componentmodel.backgroundworker [ ^ ].

—SA
You cannot restart a thread, there is no such concept (and that''s good).

You create just a new thread object and then you start it by some other thread. Since that moment, no more calls to System.Threading.Thread.Start should be done. Your problem is that you are trying to do this operation, which makes no sense. Instead, you have to let this thread terminate or abort it. If you still need the thread, you can create another one, using the same delegate instance as a constructor, or some other one.

The alternatives are using thread pool or System.ComponentModel.BackgroundWorker:
http://msdn.microsoft.com/en-us/library/system.threading.threadpool.aspx[^],
http://msdn.microsoft.com/en-us/library/vstudio/system.componentmodel.backgroundworker[^].

—SA


这篇关于我该如何解决这个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆