Question

I've done some reading on this at MSDN and around the web and now more confused than before.

I am working with a vb.net windows form application and wish to use multiple threads (but not multiple apartments).

Does this mean I need to set MTAThread attribute on the program entry point or not?

Some sources seem to indicate yes, some say a windows form app should be STA because of the COM objects, some say MTA will be set automatically when threads are created, some not... thoroughly confused now.

If I do need to set it can I do this without disabling the app framework and creating amodule to hold a Public Sub Main()?

Was it helpful?

Solution

I would consider puttin the TCPListener in a class object, with properties that the calling form can access, this class can have events your form can listen for and pass data to the UI - delegates maybe needed. The tasks could be class objects too and there can be a List(Of Task) Since they are class objects too they can now raise events which will be heard by it's owner that is listening for them. Any task that is being handled on a seperate thread will require delegates even with event raising.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top