1
votes

I Have try this. https://stackoverflow.com/a/142069/2126472

like toolStripStatusLabel1.InvokeRequired

but toolStripStatusLabel1 has no InvokeRequired

and I has try this too. https://stackoverflow.com/a/15831292/2126472

and it error like invalid argument on

SetTextCallback d = new SetTextCallback(SetText); form.Invoke(d, new object[] { form, ctrl, text });

when I use ThreadHelperClass.SetText(this, toolStripStatusLabel1, "This text was set safely.");

but not error when I use textBox

My code have method that wait for bool from another method that use Thread to run in background.

Thread t = new Thread(TestRemoteDB);
t.Start();
// In TestRemoteDB() will call updateRemoteDBStatus()

like this

private void updateRemoteDBStatus(bool successful)
        {
            if (successful)
            {
                toolStripStatusLabel4.Text = "OK!";
                toolStripStatusLabel4.ForeColor = Color.Green;
            }
            else
            {
                toolStripStatusLabel4.Text = "Error!";
                toolStripStatusLabel4.ForeColor = Color.Red;
            }
        }
1
can you paste your complete codeRohit

1 Answers

5
votes

Try this:

this.BeginInvoke((Action)(() => toolStripStatusLabel1.Text = "This text was set safely."));