473,320 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Thread Safe 'Console Log' dialog

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.

Nov 17 '05 #1
1 2070
Bry
Forgot to mention, my application creates a single public instance of
this class and is access by various other classes, as required.

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ajay | last post by:
hi! my application consists of a GUI with a number of functions. One of these runs a server in a separate thread. the thread is started and given the function start_server to execute the...
4
by: Alexander | last post by:
Hi, I have written a program that takes on some operations much more time than I expected. As I have seen users clicking wildly on the screen to make something happen, I want to follow the...
4
by: Ben Fidge | last post by:
My application uses a singleton static class for writing entries to a log file. The location and name of the log-file is read from web.config each time an entry is written, but has the current date...
5
by: Dan Tallent | last post by:
I am trying to learn how to create an application that uses worker threads to prevent the UI from freezing up. My question is: Is the following code considered "thread safe"? If not, what am I...
3
by: softwareakash | last post by:
Thread Safety I wrote a small class library written in C# which writes log messages to a log file. Everything works fine when one ASP.net application uses this dll to write text strings. The...
0
by: softwareakash | last post by:
Thread Safety I wrote a small class library written in C# which writes log messages to a log file. Everything works fine when one ASP.net application uses this dll to write text strings. The...
12
by: David | last post by:
Below are three classes for a console application. If put into three separate files, the sub main() will launch multiple threads adding and removing the same value. At the end we expect the value...
0
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
I read from a serialport using a worker thread. Because the worker thread t does not loop often, I cannot wait to terminate the worker thread using a boolean in the While condition. So I have a...
2
by: ZHENG Zhong | last post by:
Hi, I implemented a small logging library with the API like this: logger& log = log_manager::instance().get_logger("my_logger"); log.stream(DEBUG) << "this is a debug message" << std::endl;...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.