• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 655
  • Last Modified:

Better way to update form from multiple threads than InvokeRequired

i currently use something like the following to update a label which shows records getting processed:
 public void Update(int Received, int Requested)
            if (this.InvokeRequired)
                this.EndInvoke(this.BeginInvoke(new MethodInvoker(delegate() { UpdateHistTicks(Recieved, Requested); })));
                 lbHist2.Text = "Received " + Received + " out of " + Requested;    


This doesn't seem "smooth" enough. I'm wondering how I might use some sort of queue or other means to update my label? Any suggestions?
2 Solutions
Gautham JanardhanCommented:
if this method Update is in a separate thread then using the invoke is the safest option..b'coz when u use the invoke method then the code used in the delegate get executed in the thread that created the label...
You might want to try the same thing that background worker does which is to use a synchronization context. http://blogs.msdn.com/mattdotson/archive/2006/02/13/531315.aspx includes a simple example ....



Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now