Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. System ShutDown...

System ShutDown...

Scheduled Pinned Locked Moved C#
helptutorialquestioncareer
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gogou
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • G Gogou

      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

      C Offline
      C Offline
      Chris Jobson
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups