I know there is a lot of information about RaiseEvents on internet, but I can't understand them, somebody can help me with a simple example on C#.
Thanks very much.
I know there is a lot of information about RaiseEvents on internet, but I can't understand them, somebody can help me with a simple example on C#.
Thanks very much.
Insert this in your class
public event EventHandler<string> MessageHasSent;
public void SendMessage(string message)
{
EventHandler<string> ms = MessageHasSent;
if (ms!= null)
{
ms(this,message);
}
}
And in every where in your class that you want Raise this event. For example this will raise event when an error occurred
try
{
}
catch ( Exception ex)
{
SendMessage("error occurred :"+ex.Message);
}
And use it like other events