[Mono-list] Problem with Events
mono-list.1.tracyanne at spamgourmet.com
mono-list.1.tracyanne at spamgourmet.com
Thu Aug 4 03:30:28 EDT 2005
Can anyone see anything wrong with this code. It looks to me to be
correct syntax for defining and raising an event. It compiles without
error, but when I run it I get the following error message
Unhandled Exception: System.NullReferenceException: Object reference not
set to an instance of an object
in [0x00001] (at /home/tracy/MonoDevelop/TestEvents/Main.cs:22)
RaiseAnEvent:Run ()
in [0x00007] (at /home/tracy/MonoDevelop/TestEvents/Main.cs:11)
MainClass:Main (System.String[] args)
I'm using Mono_1.1.8-2.
// project created on 04/08/2005 at 17:17
using System;
class MainClass
{
public static void Main(string[] args)
{
RaiseAnEvent RAE = new RaiseAnEvent();
RAE.Run();
}
}
class RaiseAnEvent
{
public delegate void InputError(object sender, InputErrorEventArgs e);
public event InputError OnInputError;
public void Run()
{
OnInputError(this, new InputErrorEventArgs("DF", "OI"));
}
}
//Class for passing Input Error messages to the application
class InputErrorEventArgs : EventArgs
{
private string errorMessage;
private string errorSource;
public string ErrorMessage
{
get
{
return errorMessage;
}
}
public string ErrorSource
{
get
{
return errorSource;
}
}
public InputErrorEventArgs(string Message, string Source) : base()
{
errorMessage = Message;
errorSource = Source;
}
}
More information about the Mono-list
mailing list