Results 1 to 1 of 1

Thread: [resolved] [2.0] BackgroundWorker + Updating Form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Location
    City of Angles. Right Angles.
    Posts
    110

    [resolved] [2.0] BackgroundWorker + Updating Form

    I have a label on a form. I am starting another function in a backgroundworker. I want to update the label with text a few times per loop. There is a significant delay between each update, so I'm not worried about refreshing the label and hosing up the main thread.

    I don't understand how delegates work. I know that I need to invoke something in order to get the label updated. But, I don't know the syntax or how to do it. I did this code below, but I don't think it's correct and I don't know how to actually call the function without getting a Cross-Thread exception.

    Code:
            delegate void dosomestuff(string value, string binary);
            private void dosomestuffmethod(string value, string binary)
            {
                label1.Text = "Value: " + value + "\nBinary: " + binary;
            }
    Can someone point me to a tutorial or simple code snippet that will help? All the examples via google search just give me headaches. I know how to use a backgroundworker, I just need to know how to call something in a different thread.

    Thanks

    ---

    resolution:

    Code:
    delegate void del_DoSomeStuff(string value, string binary);
    private void DoSomeStuff_Method(string value, string binary)
    {
        label1.Text = "Value: " + value + "\nBinary: " + binary;
    }
    
    private void LightItUp(int val) // stripped down version of thread function
    {
        label1.Invoke(new del_DoSomeStuff(DoSomeStuff_Method), new object[] { val.ToString(), DecToBin(val) });
    }
    Last edited by supertotallyawesome; Jun 25th, 2006 at 04:59 PM. Reason: nevermind, finally figured it out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width