New theme for class instance (C #)

I have a form and several external classes (serial port, file access) that the form creates.

1) What is the easiest way to start an instance of an external class in its own thread?

2) Is the instance thread automatically terminated when the form closes?

+3
source share
3 answers

1) What is the easiest way to start an instance of an external class in its own thread?

Class instances do not start. Ways do.

As such, you can look into the APM and BackgroundWorker template .

2) Is the instance thread automatically terminated when the form closes?

, . - .

+2

, , , ThreadPool.QueueUserWorkItem. : QueueUserWorkItem() BeginInvoke()

+1

, , , , . .

UnManaged, , .

Garbage collection is periodically turned on and begins to collect all objects that go beyond. If you need to work with large objects, you can try to use the WeakReference class, which will hold the object, and also expose it to collect garbage.

Read about WeakReference and garbage collection from here: http://www.abhisheksur.com/2010/07/garbage-collection-algorithm-with-use.html

Hope this helps you.

0
source

Source: https://habr.com/ru/post/1762191/


All Articles