Click here to Skip to main content
16,011,743 members
Home / Discussions / C#
   

C#

 
GeneralRe: GridView, Trying to get some columns editable, and some columns readonly. Pin
wizardzz25-Jan-11 8:07
wizardzz25-Jan-11 8:07 
GeneralRe: GridView, Trying to get some columns editable, and some columns readonly. Pin
Eddy Vluggen25-Jan-11 8:10
professionalEddy Vluggen25-Jan-11 8:10 
GeneralRe: GridView, Trying to get some columns editable, and some columns readonly. Pin
wizardzz25-Jan-11 11:52
wizardzz25-Jan-11 11:52 
GeneralRe: GridView, Trying to get some columns editable, and some columns readonly. Pin
Eddy Vluggen26-Jan-11 0:24
professionalEddy Vluggen26-Jan-11 0:24 
AnswerRe: GridView, Trying to get some columns editable, and some columns readonly. Pin
dasblinkenlight25-Jan-11 8:11
dasblinkenlight25-Jan-11 8:11 
QuestionPlease tell me why this simple shutdown application isn't working Pin
turbosupramk325-Jan-11 3:57
turbosupramk325-Jan-11 3:57 
AnswerRe: Please tell me why this simple shutdown application isn't working Pin
Praveen Raghuvanshi25-Jan-11 4:07
professionalPraveen Raghuvanshi25-Jan-11 4:07 
GeneralRe: Please tell me why this simple shutdown application isn't working Pin
turbosupramk325-Jan-11 4:53
turbosupramk325-Jan-11 4:53 
Hi Praveen, that looks to be my problem, thank you very much.

I'm trying to incorporate it into a service I am building and it just does not work. I am probably overlooking something again, if you have any ideas, I'd love to hear them.

Thank you again for the help.





using System;
using System.Diagnostics;
using System.ServiceProcess;
using System.Threading;
using System.Windows.Forms;



namespace WindowsService
{
    class WindowsService : ServiceBase
    {
        /// <summary>

        /// Public Constructor for WindowsService.

        /// - Put all of your Initialization code here.

        /// </summary>
        /// 
        Thread thread = new Thread(new ThreadStart(shutDownBlocker));

        public WindowsService()
        {
            this.ServiceName = "AllinOneService";
            this.EventLog.Log = "Application";

            // These Flags set whether or not to handle that specific

            //  type of event. Set to true if you need it, false otherwise.

            this.CanHandlePowerEvent = true;
            this.CanHandleSessionChangeEvent = true;
            this.CanPauseAndContinue = true;
            this.CanShutdown = true;
            this.CanStop = true;
            shutDownBlocker();
            thread.Start();
        }

        /// <summary>

        /// The Main Thread: This is where your Service is Run.

        /// </summary>

        static void Main()
        {
            ServiceBase.Run(new WindowsService());
            
        }

        /// <summary>

        /// Dispose of objects that need it here.

        /// </summary>

        /// <param name="disposing">Whether

        ///    or not disposing is going on.</param>

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
        }

        /// <summary>

        /// OnStart(): Put startup code here

        ///  - Start threads, get inital data, etc.

        /// </summary>

        /// <param name="args"></param>

        protected override void OnStart(string[] args)
        {
            base.OnStart(args);
            //Thread thread = new Thread(new ThreadStart(shutDownBlocker));
            
        }

        /// <summary>

        /// OnStop(): Put your stop code here

        /// - Stop threads, set final data, etc.

        /// </summary>

        protected override void OnStop()
        {
            base.OnStop();
        }

        /// <summary>

        /// OnPause: Put your pause code here

        /// - Pause working threads, etc.

        /// </summary>

        protected override void OnPause()
        {
            base.OnPause();
        }

        /// <summary>

        /// OnContinue(): Put your continue code here

        /// - Un-pause working threads, etc.

        /// </summary>

        protected override void OnContinue()
        {
            base.OnContinue();
        }

        /// <summary>

        /// OnShutdown(): Called when the System is shutting down

        /// - Put code here when you need special handling

        ///   of code that deals with a system shutdown, such

        ///   as saving special data before shutdown.

        /// </summary>

        protected override void OnShutdown()
        {
            base.OnShutdown();
        }

        /// <summary>

        /// OnCustomCommand(): If you need to send a command to your

        ///   service without the need for Remoting or Sockets, use

        ///   this method to do custom methods.

        /// </summary>

        /// <param name="command">Arbitrary Integer between 128 & 256</param>

        protected override void OnCustomCommand(int command)
        {
            //  A custom command can be sent to a service by using this method:

            //#  int command = 128; //Some Arbitrary number between 128 & 256

            //#  ServiceController sc = new ServiceController("NameOfService");

            //#  sc.ExecuteCommand(command);


            base.OnCustomCommand(command);
        }

        /// <summary>

        /// OnPowerEvent(): Useful for detecting power status changes,

        ///   such as going into Suspend mode or Low Battery for laptops.

        /// </summary>

        /// <param name="powerStatus">The Power Broadcast Status

        /// (BatteryLow, Suspend, etc.)</param>

        protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
        {
            return base.OnPowerEvent(powerStatus);
        }

        /// <summary>

        /// OnSessionChange(): To handle a change event

        ///   from a Terminal Server session.

        ///   Useful if you need to determine

        ///   when a user logs in remotely or logs off,

        ///   or when someone logs into the console.

        /// </summary>

        /// <param name="changeDescription">The Session Change

        /// Event that occured.</param>

        protected override void OnSessionChange(SessionChangeDescription changeDescription)
        {
            base.OnSessionChange(changeDescription);
        }

        private static void shutDownBlocker()
        {
            while (true)
             {
                try
                {
                System.Diagnostics.ProcessStartInfo shutDownBlocking = new ProcessStartInfo();
                shutDownBlocking.CreateNoWindow = true;
                shutDownBlocking.FileName = @"c:\windows\system32\shutdown.exe";
                shutDownBlocking.WindowStyle = ProcessWindowStyle.Hidden;
                shutDownBlocking.Arguments = "/a";
                //Service.serviceControl.serviceStop("NBService");
                Process.Start(shutDownBlocking);
                Thread.Sleep(500);
                //MessageBox.Show("shutDownBlocker thread started");
                }
                catch (Exception ex)
                {
                    //MessageBox.Show("Error message in shutDownBlocker thread. Message reads " + ex.Message);
                }
            }
        }
    }
}

AnswerRe: Please tell me why this simple shutdown application isn't working Pin
Mirko198025-Jan-11 4:12
Mirko198025-Jan-11 4:12 
AnswerRe: Please tell me why this simple shutdown application isn't working Pin
Dave Kreskowiak25-Jan-11 4:17
mveDave Kreskowiak25-Jan-11 4:17 
GeneralRe: Please tell me why this simple shutdown application isn't working Pin
Mirko198025-Jan-11 4:25
Mirko198025-Jan-11 4:25 
GeneralRe: Please tell me why this simple shutdown application isn't working Pin
turbosupramk325-Jan-11 4:55
turbosupramk325-Jan-11 4:55 
GeneralRe: Please tell me why this simple shutdown application isn't working Pin
turbosupramk325-Jan-11 4:58
turbosupramk325-Jan-11 4:58 
GeneralRe: Please tell me why this simple shutdown application isn't working Pin
Dave Kreskowiak25-Jan-11 6:51
mveDave Kreskowiak25-Jan-11 6:51 
GeneralRe: Please tell me why this simple shutdown application isn't working Pin
turbosupramk325-Jan-11 7:18
turbosupramk325-Jan-11 7:18 
GeneralRe: Please tell me why this simple shutdown application isn't working Pin
Dave Kreskowiak25-Jan-11 8:08
mveDave Kreskowiak25-Jan-11 8:08 
QuestionHow to create a Module class in C# similar to VB .NET Pin
LAPEC25-Jan-11 1:23
LAPEC25-Jan-11 1:23 
AnswerRe: How to create a Module class in C# similar to VB .NET Pin
Estys25-Jan-11 1:29
Estys25-Jan-11 1:29 
GeneralRe: How to create a Module class in C# similar to VB .NET Pin
LAPEC25-Jan-11 1:40
LAPEC25-Jan-11 1:40 
GeneralRe: How to create a Module class in C# similar to VB .NET Pin
Pravin Patil, Mumbai25-Jan-11 1:52
Pravin Patil, Mumbai25-Jan-11 1:52 
GeneralRe: How to create a Module class in C# similar to VB .NET Pin
Estys25-Jan-11 2:17
Estys25-Jan-11 2:17 
GeneralRe: How to create a Module class in C# similar to VB .NET Pin
LAPEC25-Jan-11 2:19
LAPEC25-Jan-11 2:19 
GeneralRe: How to create a Module class in C# similar to VB .NET Pin
OriginalGriff25-Jan-11 2:25
mveOriginalGriff25-Jan-11 2:25 
GeneralRe: How to create a Module class in C# similar to VB .NET Pin
OriginalGriff25-Jan-11 2:22
mveOriginalGriff25-Jan-11 2:22 
GeneralRe: How to create a Module class in C# similar to VB .NET Pin
Estys25-Jan-11 2:01
Estys25-Jan-11 2:01 

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.