Click here to Skip to main content
15,905,963 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# class that makes program read SqlConnection string from xml file Pin
Wayne Gaylard18-Nov-11 21:44
professionalWayne Gaylard18-Nov-11 21:44 
QuestionAccessing a dynamically created drop down list Pin
Jon Myers18-Nov-11 9:21
Jon Myers18-Nov-11 9:21 
AnswerRe: Accessing a dynamically created drop down list Pin
Dan Mos19-Nov-11 8:05
Dan Mos19-Nov-11 8:05 
GeneralRe: Accessing a dynamically created drop down list Pin
Jon Myers19-Nov-11 10:21
Jon Myers19-Nov-11 10:21 
GeneralRe: Accessing a dynamically created drop down list Pin
Dan Mos19-Nov-11 10:31
Dan Mos19-Nov-11 10:31 
QuestionShutdown and Logoff System Events and Windows Services Pin
adrianojorge18-Nov-11 8:34
adrianojorge18-Nov-11 8:34 
QuestionRe: Shutdown and Logoff System Events and Windows Services Pin
Mark Salsbery18-Nov-11 10:08
Mark Salsbery18-Nov-11 10:08 
AnswerRe: Shutdown and Logoff System Events and Windows Services Pin
adrianojorge18-Nov-11 21:30
adrianojorge18-Nov-11 21:30 
Dear Mark,

I'm using Visual C# Express 2005 and i can't find the process debugger on my debug tab. But i can present you the code i'm using:
C#
using System;
using System.ServiceProcess;
using System.Threading;
using System.Windows.Forms;
using System.Diagnostics;
using Microsoft.Win32;
using System.ComponentModel;
using System.Configuration.Install;
using System.Net.Mail;

namespace SimpleServiceCs
{
    public class SimpleService : ServiceBase
    {
        static void Main(string[] args)
        {
            ServiceBase.Run(new SimpleService());
        }

        protected override void OnStart(string[] args)
        {
            EventLog.WriteEntry("SimpleService", "Starting SimpleService");
            new Thread(RunMessagePump).Start();
        }

        void RunMessagePump()
        {
            EventLog.WriteEntry("SimpleService.MessagePump", "Starting SimpleService Message Pump");
            Application.Run(new HiddenForm());
        }

        protected override void OnStop()
        {
            Application.Exit();
        }
    }

    public partial class HiddenForm : Form
    {
        public HiddenForm()
        {
            InitializeComponent();
        }

        private void HiddenForm_Load(object sender, EventArgs e)
        {
            SystemEvents.SessionEnding += new SessionEndingEventHandler(SystemEvents_SessionEnding);
        }

        private void HiddenForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            SystemEvents.SessionEnding -= new SessionEndingEventHandler(SystemEvents_SessionEnding);
        }
//****************************************************************************
//          THIS IS THE PART OF CODE STRANGELY NOT WORKING!?!?
//****************************************************************************

        private void SystemEvents_SessionEnding(object sender, EventArgs e)
        {
            EventLog.WriteEntry("System Logoff or System Shutdown");
            SendEMail("Your System is being Logged Off or Shutdown!");
        }
 
//****************************************************************************
       
        private void SendEmail(string Warning){

        //Here goes all the code necessary for sending e-mails from my personal mail account

        }


    }

    partial class HiddenForm
    {
        private System.ComponentModel.IContainer components = null;

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(0, 0);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.Name = "HiddenForm";
            this.Text = "HiddenForm";
            this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
            this.Load += new System.EventHandler(this.HiddenForm_Load);
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.HiddenForm_FormClosing);
            this.ResumeLayout(false);

        }
    }

    [RunInstaller(true)]
    public class SimpleInstaller : Installer
    {
        private ServiceInstaller serviceInstaller;
        private ServiceProcessInstaller processInstaller;

        public SimpleInstaller()
        {
            processInstaller = new ServiceProcessInstaller();
            serviceInstaller = new ServiceInstaller();

            // Service will run under system account
            processInstaller.Account = ServiceAccount.LocalSystem;

            // Service will have Start Type of Manual
            serviceInstaller.StartType = ServiceStartMode.Automatic;

            serviceInstaller.ServiceName = "Simple Service";

            Installers.Add(serviceInstaller);
            Installers.Add(processInstaller);
        }
    }
}


I'll be waiting for your feedback.
Best Regards.
GeneralRe: Shutdown and Logoff System Events and Windows Services Pin
Mark Salsbery19-Nov-11 6:21
Mark Salsbery19-Nov-11 6:21 
GeneralRe: Shutdown and Logoff System Events and Windows Services Pin
adrianojorge20-Nov-11 4:41
adrianojorge20-Nov-11 4:41 
AnswerRe: Shutdown and Logoff System Events and Windows Services Pin
SilimSayo19-Nov-11 11:22
SilimSayo19-Nov-11 11:22 
GeneralRe: Shutdown and Logoff System Events and Windows Services Pin
adrianojorge20-Nov-11 4:43
adrianojorge20-Nov-11 4:43 
AnswerMessage Removed Pin
21-Nov-11 23:46
ganeshbdas21-Nov-11 23:46 
GeneralRe: Shutdown and Logoff System Events and Windows Services Pin
adrianojorge21-Nov-11 23:51
adrianojorge21-Nov-11 23:51 
Questionchallange .net datepicker problem Pin
suma.mca.4u18-Nov-11 3:40
suma.mca.4u18-Nov-11 3:40 
AnswerRe: challange .net datepicker problem Pin
Not Active18-Nov-11 5:46
mentorNot Active18-Nov-11 5:46 
GeneralRe: challange .net datepicker problem Pin
Pete O'Hanlon18-Nov-11 8:30
mvePete O'Hanlon18-Nov-11 8:30 
GeneralMessage Removed Pin
18-Nov-11 9:22
professionalN_tro_P18-Nov-11 9:22 
GeneralRe: challange .net datepicker problem Pin
Pete O'Hanlon18-Nov-11 9:30
mvePete O'Hanlon18-Nov-11 9:30 
GeneralRe: challange .net datepicker problem Pin
djdanlib18-Nov-11 9:31
djdanlib18-Nov-11 9:31 
AnswerRe: challange .net datepicker problem Pin
Eddy Vluggen19-Nov-11 7:14
professionalEddy Vluggen19-Nov-11 7:14 
Questionhello Pin
DmitryMS18-Nov-11 2:03
DmitryMS18-Nov-11 2:03 
AnswerRe: hello Pin
Reiss18-Nov-11 2:23
professionalReiss18-Nov-11 2:23 
AnswerRe: hello Pin
Wayne Gaylard18-Nov-11 3:45
professionalWayne Gaylard18-Nov-11 3:45 
AnswerWorld PinPopular
Not Active18-Nov-11 5:44
mentorNot Active18-Nov-11 5:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.