Click here to Skip to main content
15,892,072 members
Home / Discussions / C#
   

C#

 
GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
User 680178016-Feb-10 9:42
User 680178016-Feb-10 9:42 
GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
Daniel Grunwald16-Feb-10 9:49
Daniel Grunwald16-Feb-10 9:49 
GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
User 680178016-Feb-10 9:52
User 680178016-Feb-10 9:52 
GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
Daniel Grunwald16-Feb-10 9:59
Daniel Grunwald16-Feb-10 9:59 
GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
User 680178016-Feb-10 10:31
User 680178016-Feb-10 10:31 
GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
Daniel Grunwald16-Feb-10 8:45
Daniel Grunwald16-Feb-10 8:45 
GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
User 680178016-Feb-10 9:08
User 680178016-Feb-10 9:08 
GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
Daniel Grunwald16-Feb-10 9:39
Daniel Grunwald16-Feb-10 9:39 
When you call Invoke(someDelegate); from a thread other than the GUI thread, it will send the message "please execute this delegate" to the GUI and wait until that message was processed.
That means your calculation thread is waiting for the GUI to repaint the TextBox after displaying the message!

Also, it is much faster to group several log messages and append them in a single AppendText call.
So my proposed solution was to let the background thread add log messages to a some kind of buffer (e.g. StringBuilder). A timer on the GUI thread then regularly moves the text from the buffer to the TextBox.

readonly object loggerLock = new object();
StringBuilder loggerBuffer = new StringBuilder();

private void trainingANN_instance_LogReportSynch(string stringname)
{
   // no need to invoke as we're not directly accessing tbVeryBig
   lock (loggerLock) {
      loggerBuffer.Append(stringname);
   }
}

void logTimer_Tick(object sender, EventArgs e)
{
   string newText;
   lock (loggerLock) {
      newText = loggerBuffer.ToString();
      loggerBuffer.Length = 0; // reset buffer
   } // leave lock as soon as possible so that the calculation never has to wait for long
   if (newText.Length > 0)
     tbVeryBig.AppendText(newText);
}

GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
Luc Pattyn16-Feb-10 9:45
sitebuilderLuc Pattyn16-Feb-10 9:45 
GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
User 680178016-Feb-10 10:02
User 680178016-Feb-10 10:02 
GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
User 680178016-Feb-10 10:09
User 680178016-Feb-10 10:09 
GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
User 680178017-Feb-10 7:05
User 680178017-Feb-10 7:05 
AnswerRe: Cross-Threading problem, InvokeRequired and Events Pin
#realJSOP15-Feb-10 23:21
mve#realJSOP15-Feb-10 23:21 
GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
User 680178019-Feb-10 4:10
User 680178019-Feb-10 4:10 
GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
User 680178019-Feb-10 8:06
User 680178019-Feb-10 8:06 
QuestionC# TableLayoutPanel MouseLeave Pin
ikurtz15-Feb-10 5:27
ikurtz15-Feb-10 5:27 
AnswerRe: C# TableLayoutPanel MouseLeave Pin
AhsanS15-Feb-10 5:48
AhsanS15-Feb-10 5:48 
GeneralRe: C# TableLayoutPanel MouseLeave Pin
ikurtz15-Feb-10 6:21
ikurtz15-Feb-10 6:21 
QuestionProblem using a class Pin
msg5512115-Feb-10 4:59
msg5512115-Feb-10 4:59 
AnswerRe: Problem using a class Pin
vaghelabhavesh15-Feb-10 5:04
vaghelabhavesh15-Feb-10 5:04 
GeneralRe: Problem using a class Pin
msg5512115-Feb-10 5:31
msg5512115-Feb-10 5:31 
GeneralRe: Problem using a class Pin
vaghelabhavesh15-Feb-10 5:53
vaghelabhavesh15-Feb-10 5:53 
QuestionIP Address Pin
sanforjackass15-Feb-10 4:16
sanforjackass15-Feb-10 4:16 
AnswerRe: IP Address Pin
Migounette15-Feb-10 4:18
Migounette15-Feb-10 4:18 
GeneralRe: IP Address Pin
sanforjackass15-Feb-10 4:43
sanforjackass15-Feb-10 4:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.