Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can MessageBox.Show cause cross-thread exceptions?

Can I call MessageBox.Show on a child thread without worrying about a cross-thread exception? I know the ostensible answer would be "try it and find out", which I did, successfully, but I've noticed that Windows 7 seems to be less strict about raising cross-thread exceptions than Windows XP.

So, is it documented anywhere that this would be safe to do from a child thread?

like image 248
Adam Rackis Avatar asked Mar 24 '11 15:03

Adam Rackis


2 Answers

If you call MessageBox.Show("text") without an owner window you are save. If you call MessageBox.Show like MessageBox.Show(this,"text") specifying the owner window things are different.

I have seen that in Windows XP you are save but in Windows 7 you will run into a cross-thread exception if the owner window is running in a different thread than the thread from which you call the MessageBox!

like image 111
Ulrich Schmid Avatar answered Sep 22 '22 00:09

Ulrich Schmid


No, it will not cause any "cross-thread" exceptions. That's because the MessageBox is not a member of a class running on the UI thread.

like image 43
Mike Dinescu Avatar answered Sep 24 '22 00:09

Mike Dinescu