Click here to Skip to main content
15,912,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I try to close may program using Application.Exit();

The problem is a have to write same data i my database, if i use FormClosing even i enter n a loop.

Any suggestions?

C#
DialogResult ConfirmareInchidereProgram = winCustomDialog.ShowBox("NU UITAȚI SĂ ADĂUGAȚI VALOZARE RAPORTULUI Z ÎN REGISTRU DE CASĂ.\n\nSunte-ți sigur că doriți să închideți aplicația?", "Închidere aplicație", "Închide aplicația", "Anulează", true);
           if (ConfirmareInchidereProgram == DialogResult.No)
           {
              return;
           }


           SetariProgram.SoldFinal = SetariAmanet.ObtineSoldFinal();
           SetariAmanet.RaportDegestiune();


           Application.Exit();
Posted
Comments
Richard MacCutchan 12-Feb-14 4:15am    
You can update your database in the FormClosing event. Where are you calling Application.Exit from?

1 solution

i modified my code like this:

C#
void frmContacts_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult ConfirmareInchidereProgram = winCustomDialog.ShowBox("NU UITAȚI SĂ ADĂUGAȚI VALOZARE RAPORTULUI Z ÎN REGISTRU DE CASĂ.\n\nSunte-ți sigur că doriți să închideți aplicația?", "Închidere aplicație", "Închide aplicația", "Anulează", true);
            if (ConfirmareInchidereProgram == DialogResult.No)
            {
                e.Cancel = true;
                return;
            }
            else
            {
                SetariProgram.SoldFinal = SetariAmanet.ObtineSoldFinal();
                SetariAmanet.RaportDegestiune();
                FormClosing -= frmContacts_FormClosing;
            }
        }


and now is ok, is working.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900