我有一个表单和几个外部类(串行端口,文件访问),由表单实例化。
1)在自己的线程中运行外部类的实例最简单的方法是什么?
2)表单关闭时,实例的线程是否自动终止?
I have a form and several external classes (serial port, file access) that are instantiated by the form.
1) What's the simplest way to run an instance of an external class in its own thread?
2) Is the instance's thread automatically terminated when the form closes?
最满意答案
1)在自己的线程中运行外部类的实例最简单的方法是什么?
类的实例不“运行”。 方法呢。
因此,您可能希望查看APM模式和BackgroundWorker类。
2)表单关闭时,实例的线程是否自动终止?
这取决于线程的启动方式。 线程可以是后台线程或前台线程 - 后者阻止应用程序终止。
1) What's the simplest way to run an instance of an external class in its own thread?
Instances of classes do not "run". Methods do.
As such, you may want to look into the APM pattern and the BackgroundWorker class.
2) Is the instance's thread automatically terminated when the form closes?
It depends on how the threads were started. A thread can be a background thread or a foreground thread - the latter prevents the application from terminating.
更多推荐
发布评论