Reputation: 744
I want to run parts of my winform usercontrol (which are also usercontrols) as threads or even as new processes. But they still should be in the main winform. Is this possible?
Upvotes: 0
Views: 1046
Reputation: 744
Solution is to start a WinForm as standalone-process and then host it in your own window using the user32.dll - just like described here:
Upvotes: 0
Reputation: 157038
No. UserControl
, and all other UI elements should be created on the main (UI) STA thread. Period. Cross-thread operations are not allowed.
You can take other parts of the control to another thread, but not as long as UI elements are involved (or you should use Control.Invoke
when accessing them).
For parallel processing you have some nice features in .NET including the Task Parallel Library (TPL), including Task
.
So for some calculations, you could do:
Task.Run( () => SomeHeavyMethod(1, 2, 3) );
But inside, you can't use UI elements, without using Invoke
.
Upvotes: 2