-3

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.

MagnunStalin
  • 94
  • 1
  • 9
  • You need to be much more specific. What part exactly is giving you a problem. StackOverflow isn't a grinds website. – James May 16 '16 at 15:36
  • @judgeja - even as someone from the UK I had to look up the meaning of "grinds" in that context. – Jamiec May 16 '16 at 15:37
  • http://stackoverflow.com/questions/6644247/simple-custom-event – mohsen May 16 '16 at 15:44

1 Answers1

1

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

mohsen
  • 1,763
  • 3
  • 17
  • 55