C# Delegate Invoke Required Issue

Posted by Goober on Stack Overflow See other posts from Stack Overflow or by Goober
Published on 2010-04-12T09:14:43Z Indexed on 2010/04/12 9:23 UTC
Read the original article Hit count: 522

Filed under:
|

Scenario

I have a C# windows forms application that has a number of processes. These processes run on separate threads and all communicate back to the Main Form class with updates to a log window and a progress bar. I'm using the following code below, which up until now has worked fine, however, I have a few questions.

Code

     delegate void SetTextCallback(string mxID, string text);
     public void UpdateLog(string mxID, string text)
     {
         if (txtOutput.InvokeRequired)
         {
            SetTextCallback d = new SetTextCallback(UpdateLog);
            this.BeginInvoke(d, new object[] { mxID, text });
         }
         else
         {
            UpdateProgressBar(text);
         }
     } 

Question

Will, calling the above code about 10 times a second, repeatedly, give me errors, exceptions or generally issues?.....Or more to the point, should it give me any of these problems?

Occasionally I get OutofMemory Exceptions and the program always seems to crash around this bit of code......

© Stack Overflow or respective owner

Related posts about c#

Related posts about delegate