S Schearer

S Schearer

  • NA
  • 3
  • 0

How do I handle a situation that needs to destroy an object in C#?

Apr 6 2010 2:10 PM

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...

Answers (2)