I'm getting a stackverflow error while executing InvokeRequired.
System.StackOverflowException was unhandled

How to fix it? There is no info i View Details.
FIXED VERSION:
public DialogResult ShowMessage(string msg, string caption, MessageBoxButtons buttons)
{
if (InvokeRequired)
{
Func<DialogResult> m = () => MessageBox.Show(msg, caption, buttons);
return (DialogResult)Invoke(m);
}
else
{
return MessageBox.Show(msg, caption, buttons);
}
}
It's because when
InvokeRequiredis true, you call the exact same method again and again. You need to useInvokein order to get the method scheduled to run on the UI thread. In this case,InvokeRequiredwill be false, and your code will run into theifbranch where you actually show the dialog.Change your code to something along the lines of: