Thread Safe 'Console Log' dialog

  • Thread starter Thread starter Bry
  • Start date Start date
B

Bry

I have a simple Windows form class called Console. The form comprises
solely of a RichTextBox.

I recently added multi threading to my application and as a result I've
started having problems when I try to call the .Show() method for the
form, so I implemented a delegate as follows:


delegate void cb_ShowConsole();

// - - 8< - - irrelevant code snipped - - 8< - -

private void ts_ShowConsole()
{
// Thread safe call to the Console.Show() method

if (InvokeRequired)
{
cb_ShowConsole d = new cb_ShowConsole(ts_ShowConsole);
this.Invoke(d, new Object[] { });
}
else
{
myConsole.Show(); // ***** THIS LINE CAUSES THE
EXCEPTION ****
}
}

however I receive a "InvalidOperationExcpetion" on the highlighted line
above.

I have used this method in other places throughout my code with
success, however this section of code does not work.

Can anyone see what I'm doing wrong?

Thanks,
Bry.
 
Forgot to mention, my application creates a single public instance of
this class and is access by various other classes, as required.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top