Form Closed Event is not being fired
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.
精彩评论