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.
Here is my class:
public class MyClass
{
public MyClass()
{
}
/// <summary>
/// MyClass is closing
/// </summary>
public event EventHandler MyClassClosing;
public void OnMyClassClosing(EventArgs
{
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.
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);
}
public delegate MyClassClosingEventHandler
public event MyClassClosingEventHandler
~ MyClass()
{
//do whatever you would do for your class closing?
if(MyClassClosing != null)
{ MyClassClosing(this, e);
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK, but the runtime destructs my object. I need to destruct the object by myself.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@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! :-)
Cheers,
Aaron
http://aaronfeng.blogspot.com/