Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to invoke MessageBox calls?

To pop-up a message box, I'm using MessageBox.Show(...). I usually wrap the call in an Invoke:

BeginInvoke (new Action (() => {
    MessageBox.Show ());
}));

(I removed a part of the original question which was answered elsewhere)

Do I always need to wrap the MessageBox call in an (Begin-)Invoke if I'm calling from a non-GUI thread?

like image 323
mafu Avatar asked Nov 15 '22 10:11

mafu


1 Answers

Short answer: yes, because I would consider it a best practice.

Longer answer:

You should not get into a situation where you have to ask yourself this question, at least not in the long run. Usually, in a well designed piece of software, you have defined "gateways" between the user interface and the "rest of the world", this would also be the place where you raise the events that notify the GUI that something has to be done (via BeginInvoke(EventRaiserMethod(params))).

like image 99
stormianrootsolver Avatar answered Dec 05 '22 10:12

stormianrootsolver