Link to home
Start Free TrialLog in
Avatar of noulouk
noulouk

asked on

Close a class

Hi Experts,

Here is my class:
public class MyClass
    {
        public MyClass()
        {
         }

        /// <summary>
        /// MyClass is closing
        /// </summary>
        public event EventHandler MyClassClosing;

        public void OnMyClassClosing(EventArgs e)
        {
            if (MyClassClosing != null)
                MyClassClosing(this, e);
        }
     }

I need to close the class programmatically. So when I decide to close the class, I raise the MyClassClosing event to inform the user and then I close the class.

The problem is that I don't know how to close my class.

Thanks in advance for your answers.
Avatar of aaronfeng
aaronfeng

Can you define "close my class"?  Not sure what you mean by it.

Cheers,

Aaron
http://aaronfeng.blogspot.com/
how about using a destructor for your class? (maybe a syntax error... not tested or anything)

public delegate MyClassClosingEventHandler(object sender, System.EventArgs e)
public event MyClassClosingEventHandler MyClassClosing;

~ MyClass()
{
    //do whatever you would do for your class closing?
    if(MyClassClosing != null)
    {   MyClassClosing(this, e);
}
SOLUTION
Avatar of PoeticAudio
PoeticAudio

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of noulouk

ASKER

OK, but the runtime destructs my object. I need to destruct the object by myself.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@anyoneis: Sorry for the repetition, I was writing my comment when you posted yours
@TheAvenger: No problemo - it happens and the two responses make for a more complete answer - hopefully one that works for noulouk! :-)