I have a GUI that creates an object when the user hits the start button. In the object's initialization method other objects are created and processes are started.
If the object's initialization fails, I want to recreate the object. The object needs to be destroyed before it can be recreated because some processes are started in the initialization routine and they don't end until the object goes out of scope.
In C++ I would have just called the object's destructor.
Can someone please tell me how to solve this problem in C#?
I was told to just restart the program, but that seems hokey...
Loading
Sam HobbsPosted Apr 6, 2010, 9:57 PM
Generally, we don't need to do anything special to dispose of an object unless the object has unmanaged objects. I am not an expert and there are probably exceptions but that is what I have read.
I think the dispose, or the equivalent, will be done automatically when we assign another instance of an object. So in other words, just do another "new". Or set the reference to null. You could try that by overriding dispose so you can diagnose when it gets called.
Does that help?
S SchearerPosted Apr 8, 2010, 10:06 AM
Thanks!