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. Window Service problem

Window Service problem

Scheduled Pinned Locked Moved C#
help
3 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.
  • Y Offline
    Y Offline
    Yulianto
    wrote on last edited by
    #1

    I have the following code. I've install the service, and start it. I want to create a file 'c:\test.txt' using the timer. But the file still can't be created. I've check for Application error at windows 'event viewer', but have not find any.

    using System;
    using System.Diagnostics;
    using System.ServiceProcess;
    using System.IO;

    namespace WindowsService
    {
    class WindowsService : ServiceBase
    {
    private System.Windows.Forms.Timer timer1;
    private System.ComponentModel.IContainer components;

        public WindowsService()
        {
            this.ServiceName = "G-ERP Auto backup";
            this.EventLog.Source = "G-ERP Auto backup";
            this.EventLog.Log = "Application";
            
            this.CanHandlePowerEvent = true;
            this.CanHandleSessionChangeEvent = true;
            this.CanPauseAndContinue = true;
            this.CanShutdown = true;
            this.CanStop = true;
    
            InitializeComponent();
    
            if (!EventLog.SourceExists("G-ERP Auto backup"))
                EventLog.CreateEventSource("G-ERP Auto backup", "Application");
        }
    
        static void Main()
        {
            ServiceBase.Run(new WindowsService());
        }
    
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
        }
    
        protected override void OnStart(string\[\] args)
        {
            this.timer1.Enabled = true;
            base.OnStart(args);
        }
    
        protected override void OnStop()
        {
            this.timer1.Enabled = false;
            base.OnStop();
        }
    
        protected override void OnPause()
        {
            this.timer1.Enabled = false;
            base.OnPause();
        }
    
        protected override void OnContinue()
        {
            this.timer1.Enabled = true;
            base.OnContinue();
        }
    
        protected override void OnShutdown()
        {
            base.OnShutdown();
        }
    
        protected override void OnCustomCommand(int command)
        {
    
            base.OnCustomCommand(command);
        }
    
        protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
        {
            return base.OnPowerEvent(powerStatus);
        }
    
        protected override void OnSessionChange(SessionChangeDescription changeDescription)
        {
            base.OnSessionChange(changeDescription);
        }
    
        private void InitializeComponen
    
    A 1 Reply Last reply
    0
    • Y Yulianto

      I have the following code. I've install the service, and start it. I want to create a file 'c:\test.txt' using the timer. But the file still can't be created. I've check for Application error at windows 'event viewer', but have not find any.

      using System;
      using System.Diagnostics;
      using System.ServiceProcess;
      using System.IO;

      namespace WindowsService
      {
      class WindowsService : ServiceBase
      {
      private System.Windows.Forms.Timer timer1;
      private System.ComponentModel.IContainer components;

          public WindowsService()
          {
              this.ServiceName = "G-ERP Auto backup";
              this.EventLog.Source = "G-ERP Auto backup";
              this.EventLog.Log = "Application";
              
              this.CanHandlePowerEvent = true;
              this.CanHandleSessionChangeEvent = true;
              this.CanPauseAndContinue = true;
              this.CanShutdown = true;
              this.CanStop = true;
      
              InitializeComponent();
      
              if (!EventLog.SourceExists("G-ERP Auto backup"))
                  EventLog.CreateEventSource("G-ERP Auto backup", "Application");
          }
      
          static void Main()
          {
              ServiceBase.Run(new WindowsService());
          }
      
          protected override void Dispose(bool disposing)
          {
              base.Dispose(disposing);
          }
      
          protected override void OnStart(string\[\] args)
          {
              this.timer1.Enabled = true;
              base.OnStart(args);
          }
      
          protected override void OnStop()
          {
              this.timer1.Enabled = false;
              base.OnStop();
          }
      
          protected override void OnPause()
          {
              this.timer1.Enabled = false;
              base.OnPause();
          }
      
          protected override void OnContinue()
          {
              this.timer1.Enabled = true;
              base.OnContinue();
          }
      
          protected override void OnShutdown()
          {
              base.OnShutdown();
          }
      
          protected override void OnCustomCommand(int command)
          {
      
              base.OnCustomCommand(command);
          }
      
          protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
          {
              return base.OnPowerEvent(powerStatus);
          }
      
          protected override void OnSessionChange(SessionChangeDescription changeDescription)
          {
              base.OnSessionChange(changeDescription);
          }
      
          private void InitializeComponen
      
      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      Yulianto. wrote:

      File.Copy(@"c:\YServer.txt", @"c:\test.txt"); if (!File.Exists(@"c:\YServer.txt")) { File.Copy(@"c:\YServer.txt", @"c:\test.txt"); }

      File.Copy(@"c:\YServer.txt", @"c:\test.txt");
      if (!File.Exists(@"c:\YServer.txt"))
      {
      File.Copy(@"c:\test.txt",@"c:\YServer.txt");
      }

      Check the difference on the bold line

      Bob Ashfield Consultants Ltd

      Y 1 Reply Last reply
      0
      • A Ashfield

        Yulianto. wrote:

        File.Copy(@"c:\YServer.txt", @"c:\test.txt"); if (!File.Exists(@"c:\YServer.txt")) { File.Copy(@"c:\YServer.txt", @"c:\test.txt"); }

        File.Copy(@"c:\YServer.txt", @"c:\test.txt");
        if (!File.Exists(@"c:\YServer.txt"))
        {
        File.Copy(@"c:\test.txt",@"c:\YServer.txt");
        }

        Check the difference on the bold line

        Bob Ashfield Consultants Ltd

        Y Offline
        Y Offline
        Yulianto
        wrote on last edited by
        #3

        Thanks. But i did not solve the problem


        Work hard, Work effectively. Stock Pick | Small Website Host

        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