• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 658
  • 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 ....


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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