开发者

Form Closed Event is not being fired

开发者 https://www.devze.com 2023-03-19 19:06 出处:网络
When the Application is being closed from Task Manager ,than Form_Closed E开发者_如何学Cvent is not firing ,is there a way how to handle this ,because my Application is writing a text file on run-time

When the Application is being closed from Task Manager ,than Form_Closed E开发者_如何学Cvent is not firing ,is there a way how to handle this ,because my Application is writing a text file on run-time always ,so i need to finalize data which holds a thread and close the StreamWriter on Form_Closed ,so how to handle that no matter how my Application is being Closed ,From User ,ALT+f4 or Task Manager


Implement the IDisposable interface and call Dispose() on the StreamWriter from there.


To get this case you need to handle the Application.Exit event.

Occurs just before an application shuts down, and cannot be canceled.

Here you can make sure that all data is written to the file and it's closed properly - if it's not already closed of course.

0

精彩评论

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