Cross-thread ToolStripButton update
-
I generally use this method to update buttons cross-thread, but ToolStripButtons don't have the InvokeRequired property. delegate void UpdateStartDelegate(bool newState); private void updateStartButton(bool newState) { if (startButton.InvokeRequired) // is cross-thread update Invoke(new UpdateStartDelegate(updateStartButton), new object[] { newState }); else startButton.Enabled = newState; } Is there an easy way to do the same thing with a ToolStripButton?
-
I generally use this method to update buttons cross-thread, but ToolStripButtons don't have the InvokeRequired property. delegate void UpdateStartDelegate(bool newState); private void updateStartButton(bool newState) { if (startButton.InvokeRequired) // is cross-thread update Invoke(new UpdateStartDelegate(updateStartButton), new object[] { newState }); else startButton.Enabled = newState; } Is there an easy way to do the same thing with a ToolStripButton?
((Control)btn).InvokeRequired
only two letters away from being an asset
-
I generally use this method to update buttons cross-thread, but ToolStripButtons don't have the InvokeRequired property. delegate void UpdateStartDelegate(bool newState); private void updateStartButton(bool newState) { if (startButton.InvokeRequired) // is cross-thread update Invoke(new UpdateStartDelegate(updateStartButton), new object[] { newState }); else startButton.Enabled = newState; } Is there an easy way to do the same thing with a ToolStripButton?
use a synchronous calls using a timer
-
((Control)btn).InvokeRequired
only two letters away from being an asset
-
All ToolStripItems (suach as ToolStripButton) are only of type Component. They don't inherit from Control. Regards.
You're correct, my mistake
only two letters away from being an asset
-
I generally use this method to update buttons cross-thread, but ToolStripButtons don't have the InvokeRequired property. delegate void UpdateStartDelegate(bool newState); private void updateStartButton(bool newState) { if (startButton.InvokeRequired) // is cross-thread update Invoke(new UpdateStartDelegate(updateStartButton), new object[] { newState }); else startButton.Enabled = newState; } Is there an easy way to do the same thing with a ToolStripButton?
I apologize for posting on an old thread, but I had the exact same question, and there did not seem to be an answer to this one. Someone mentioned using a timer, but my cross-thread could take several seconds, several minutes, or several hours. I think I came up with an answer, so for future searchers I decided to post. I would test the ToolStrip that contained the button. This code seems to work to enable a toolstripbutton when a thread is done.
public void Enable() { if (toolStrip.InvokeRequired) { EnableButtonCallback d = new EnableButtonCallback(Enable); toolStrip.Invoke(d, new object[] { }); } else { button.Enabled = true; } }