Window Service problem
-
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
-
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
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
-
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
Thanks. But i did not solve the problem
Work hard, Work effectively. Stock Pick | Small Website Host