Hi,
I randomly observe this
System.InvalidOperationException: Value Dispose() cannot be called while doing CreateHandle().
exception on click of Winform Close button operation.
On Close button click event, I just close the form by calling form Close function.
I have defined an EventHandler for on Form "Closed" operation. Within the EventHandler I m stopping the Timer and calling Timer.Dispose() function. I define and start this Timer on Form load. The Timer is of type System.Windows.Forms.Timer().
Since this is WinForms Timer I believe this will be executed by UI thread. Before stopping the Timer I also check if its Enabled or not. If its Enabled I will Stop it, else I Dispose it off.
There are multiple Timer of the same type defined within the application. Is it possible that one timer affects the other in any way?.
A NOTE provided in MSDN link
Timer.Stop Method (System.Windows.Forms)[
^] suggest something like this.
Any help in resolving this exception is appreciated.
Thanks.
What I have tried:
I unsubscribed the Timer.Tick eventhandler, within the form Close and tested the same. But the exception still persists.