System ShutDown...
-
Hi, In my program I need after doing some job to be able to shut down the system. So I wrote that code: public event SessionEndedEventHandler ShutDown; protected virtual void OnShutDown(SessionEndedEventArgs e) { ShutDown(this,e); } and then I wanted on a button click to raise the event: private void button1_Click(object sender, System.EventArgs e) { OnShutDown(new SessionEndedEventArgs(SessionEndReasons.SystemShutdown)); } But I always get System.NullReferenceException Anyone has an idea how to solve this problem:confused:? Thanx in advance Cheers, Gogou GAtanasov
-
Hi, In my program I need after doing some job to be able to shut down the system. So I wrote that code: public event SessionEndedEventHandler ShutDown; protected virtual void OnShutDown(SessionEndedEventArgs e) { ShutDown(this,e); } and then I wanted on a button click to raise the event: private void button1_Click(object sender, System.EventArgs e) { OnShutDown(new SessionEndedEventArgs(SessionEndReasons.SystemShutdown)); } But I always get System.NullReferenceException Anyone has an idea how to solve this problem:confused:? Thanx in advance Cheers, Gogou GAtanasov
Hi, I think that OnShutDown should check that there is a handler for the event, i.e. the code should be: if (ShutDown != null) ShutDown(this, e); Chris Jobson