开发者

How to dispose of variables in windows close button

开发者 https://www.devze.com 2022-12-26 20:06 出处:网络
I ha开发者_开发知识库ve a windows forms application, where I have declared some static variables.

I ha开发者_开发知识库ve a windows forms application, where I have declared some static variables. On the click of exit button, I have disposed of some datatable which i have declared static.

Many a times the user instead of clicking the exit button, will just exit the windows application by clicking the X button on the left corner top.

What should be done to ensure that even if the user clicks the X button, everything is disposed of properly.

Thanks

Regards

Hema


This question has some good descriptions of events that you can hook into to detect when a application is exiting.

Does Application.ApplicationExit event work to be notified of exit in non-Winforms apps?


Just add a delegate function to the Closing event of the form.

this.Closing += this.MyForm_Closing;

You can also use the Closed event of the form if you'd prefer it gets called after the form is closed.


You can add an event handler to dispose your variables when the form is closing.

private: System::Void myDialog_FormClosing(System::Object^  sender, System::Windows::Forms::FormClosingEventArgs^  e) {
         // Dispose your static variables here
     }
0

精彩评论

暂无评论...
验证码 换一张
取 消