I am developing a chat application with C# and we are using System.Timer.Timer for frequently getting data for the new request and zone request.
It is running fine but whenever we create a new instance a cross threaded operation exception occurs.
This is my code:
frmchat f = new frmchat();
MethodInvoker method = new MethodInvoker(delegate()
{
f.Name = "xyz";f.Show();
});
if (f.InvokeRequired)
{
f.Invoke(method);
}
else
{
method();
}
This will create a number of chat forms.
If you are creating that form at the elapsed event handler of that timer then use
this.Invokeinstead, like: