类的实例的新线程(C#)(New Thread for Instance of a Class (C#))

编程入门 行业动态 更新时间:2024-10-23 07:32:59
类的实例的新线程(C#)(New Thread for Instance of a Class (C#))

我有一个表单和几个外部类(串行端口,文件访问),由表单实例化。

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.

更多推荐

本文发布于:2023-07-24 10:52:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1245003.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   实例   Thread   Instance   Class

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!