Try to exploit the following idea. Check if Invoke is required
(this is the only thread-safe property of a control) and if it is,
Invoke a delegate initialized with your changeProgressBar method
instead of calling it directly.
// declare delegate signature
private delegate void ChangeProgressBarCallback();
private void changeProgressBar()
{
if(toolStripProgressBar1.InvokeRequired)
{
// instantiate the callback instance out of this very method
ChangeProgressBarCallback callback = new ChangeProgressBarCallback(changeProgressBar);
// invoke it, when it comes to it again InvokeRequired will be false
Invoke(callback);
}
else
{
toolStripProgressBar1.Maximum = 100;
for (int i = 0; i <= 100; i++)
{
toolStripProgressBar1.Value = i;
if (i == 100)
{
for (int j = 100; j >= 0; j++)
{
toolStripProgressBar1.Value = j;
}
i = 0;
}
}
}
}
Thanks for your answer!
Sericinus hunter schrieb:
> Try to exploit the following idea. Check if Invoke is required
> (this is the only thread-safe property of a control) and if it is,
> Invoke a delegate initialized with your changeProgressBar method
> instead of calling it directly.
> [...]
> if(toolStripProgressBar1.InvokeRequired)
The ToolStripProgressBar does not has a property "InvokeRequired" :-(
Sericinus hunter - 20 Nov 2006 22:29 GMT
Ah, I did not realize that, since never used this control myself.
However, I found the suggestion somewhere on the web, that you
can check this property with any other control (you can probably
create one, hidden, just for this very purpose):
http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.windowsform
s/topic43420.aspx
> Thanks for your answer!
>
[quoted text clipped - 7 lines]
>
> The ToolStripProgressBar does not has a property "InvokeRequired" :-(