tags:

views:

560

answers:

5

I have a created a custom keyboard shortcut for my application, when the user press combination keys of CTRL + ALT + Q, i show a messagebox "Are you sure you want to log out ?" Then if clicked YES, i log out of the application.

Problem : I want to make sure that, only once instance of message box shows. No matter how many times the user presses the shortcut.

currently it shows multiple message box, on pressing multiple shortcuts.

How to overcome this ?

+1  A: 

A quick and dirty way would be to have a class level boolean variable that tracks when the user is trying to exit. If they are, it's set to true, and your routine to display the dialog box can check this flag, then return without doing anything.

Michael Todd
A: 

Seems like Singleton Pattern is your option.

nairdaen
runs screaming ;p
johnc
The question is about `MessageBox.Show`, which is a static method of a static class `MessageBox`. There are no objects involved here, at all.
Pavel Minaev
A: 

You'll want to make your application single instance so it can only be started once.

Single Instance App

Paul Alexander
A: 

I think you can create your own form and use the mymessageboxform.show() method, and check its dialogue result.

+2  A: 

From MSDN

A message box is a modal dialog box, which means no input (keyboard or mouse click) can occur except to objects on the modal form. The program must hide or close a modal form (typically in response to some user action) before input to another form can occur.

File a bug on connect.microsoft.com !


Taking ck's comment into consideration...If you are showing a custom dialog (form) then you need to invoke the form using Form.ShowDialog() and not Show().

This must mean he has a custom form for confirmation, as no MS software would ever have any bugs...?
ck
Even though I think "no MS software would ever have any bugs" is debatable I think you have a point! The question does not say that he is using the MessageBox class.