solution for performing final work when winform is no longer needed
I need to accomplish the following.
1.) I have a winform (winformA) that is hidden instead of closed
2.) the winform in #1 is a child to the mainform, when i shutdown the mainform, the child form WinformA is disposed. I need to save data from a winform control in the winformA
The content is in a ListView in WinformA. I have tried overriding the dispose and using the destructor ~classname, but the listview items are null at that point. I cannot do it in form closing because i dont want the action to take place until the whole app is being shutdo开发者_Go百科wn. I cannot expose the method to the mainform due to security requirements. I have tried subscribing to Application.ApplicationExit but the event does not fire.
Any idea?
I cannot do it in form closing
You have to do it from your FormClosing event handler. Pay attention to the e.CloseReason value.
Fwiw, the 'security requirements' are a pipe dream with System.Reflection in a programmer's arsenal. You'll have to setup a sandbox to prevent that.
Can you save your items to a variable instead of a UI control?
Then maybe it won't be null when you reference it.
精彩评论