At work we've got a very CPU-intensive Windows Forms application. It's running on a server with 24 cores.
As the Windows Forms model involves a single GUI thread processing a message pump, it seems that a rich, complex GUI is not making good use of the capabilities of the system. Am I wrong in saying this?
So my coworkers were discussing this. Our application just happens to involve two more-or-less independent forms. The idea came up to have the auxiliary form operate on its own dedicated thread, freeing up the app's main GUI thread to only process messages sent to the main form.
Presumably this would look something rather like this:
void CreateAuxiliaryForm()
{
Action displayForm = () =>
{
var f = new AuxiliaryForm();
f.ShowDialog();
};
displayForm.BeginInvoke(displayForm.EndInvoke, null);
}
Now, first of all, I don't know if this is safe to do at all. But my thinking is that since the two forms will be independent, it really ought to be OK for each one to have its own thread. Is this true?
I did say "more-or-less," and that's because I can't really say the two forms have no interaction whatsoever. But what my coworkers and I figured was that in any scenario in which the main form has to interact with the auxiliary form in some way (say by one handling an event raised by the other), we would simply need to be sure to use Invoke
/BeginInvoke
to send any GUI-related code to the appropriate message pump.
What are people's thoughts on this idea?