lundi 23 février 2015

show message box on cross thread with owner

I want to show MessageBox on cross thread with providing owner object.like this :



if (MessageBox.Show(mainform,"message", "title", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Cancel)
{
return true;
}


by this code I am getting exception :



Cross-thread operation not valid: Control 'MainForm' accessed from a thread other than the thread it was created on.



I tied with checking InvokeRequired of mainform but still it's throwing same exception.


Aucun commentaire:

Enregistrer un commentaire