.net - Ask confirmation message only once from user in C# Window Appliaction -


i built windows application using c# .

on form closing event wrote code ask confirmation form user...

private void approve_user_formclosing(object sender, formclosingeventargs e)         {             if (messagebox.show("do want quit application...?", "confirmation", messageboxbuttons.yesno, messageboxicon.question) == dialogresult.yes)             {                  application.exit();             }             else             {                 e.cancel = true;             }          } 

sometimes ask 4 times , upto 5 times....

i want once if user press yes application should exit.

i need , suggestions. in advance.

apparently subscribing approve_user_formclosing event in place execute few times. if subscribe 4,5 times execute 4,5 times.

if want capture application exit event have @ this thread.

edit

you need below achieve weird requirement.

private bool isexiting = false;  private void approve_user_formclosing(object sender, formclosingeventargs e)         {             if (isexiting)                    return;              if (messagebox.show("do want quit application...?", "confirmation", messageboxbuttons.yesno, messageboxicon.question) == dialogresult.yes)             {                 isexiting = true;                 application.exit();             }             else             {                 e.cancel = true;             }          } 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -