+ Reply to Thread
Results 1 to 2 of 2

Thread: Shutting down pc using timer

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    36

    Shutting down pc using timer

    I am trying to shutdown a pc after a timer has been ticked , i don't know how to shutdown the pc programmatically
    Last edited by cpro; 11-01-2012 at 03:11 PM.

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    35
    I`ll give you an example that uses a timer and when timer ticks it will shutdown the pc.

    Example :
    Code:
            System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
    
            private void Shutdown()
            {
                System.Diagnostics.Process.Start("Shutdown", "-s -t 0");
    
                t.Enabled = false;
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                t.Interval = 1000; // 1000 = 1 second
                t.Enabled = true;
                t.Tick += delegate { Shutdown(); };
            }
    Hint :
    - Delegates can be used to define callback methods like the above example , in timer tick i delegated the Shutdown Function to shutdown the pc.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts