If I turn off child form, does it automatically turn off thread for tcp running in child form?

23 Views Asked by At

I have two Winform application(.net) server app A and client app B.

client will open a child form to receive data from server through TCP protocol and display the data on child form. client will open multiple forms for display different data from server. and I will run socket with multi threading.

the question is if I quit those child forms then all the resources for child form (include threads) will be dispose or terminate ? I worried there would be leak

1

There are 1 best solutions below

0
JonasH On

A form does not "own" resources like threads. If you start a thread when loading the form you also need to ensure the thread is shutdown cleanly. Typically by asking the worker thread to shutdown, and then waiting for it to complete its shutdown process. The same goes for anything that implements IDisposable, if you create it yourself you need to dispose it.

There are events on the form you can use to run code when the form closes.