Reputation: 13592
I have a Windows Service consisting of a timer with 4000 Interval, in tick method of timer a save method run and save a bitmap file in specific path, it is like the following:
protected override void OnStart(string[] args) {
CaptureTimer.Start();
}
private void CaptureTimer_Tick(object sender, EventArgs e) {
DateTime dt = DateTime.Now;
Bitmap capture = Capture.GetImage();
capture.Save(@"D:\Doc\Temp\GeoServiceFiles\" + Environment.MachineName +
dt.Ticks.ToString() + ".bmp");
}
but there is not any saved file, I test the exact code in Win Application and that worked correctly replaced OnStart method with button1_Click. also for test my service add an eventlog: eventLog1.WriteEntry("test service");
and log saved correctly but yet there isn't any saved file, So is there any special way to saved files with Windows Services?
Upvotes: 1
Views: 3450
Reputation: 13592
What Timer you use? I think you must use System.Threading.Timer
look at this Use of Timer in Windows Service
Upvotes: 1
Reputation: 60744
Have you checked the permissions on the folder D:\Doc\Temp\GeoServiceFiles\
?
The windows service usually run as Local System, Network Service or similar depending on how you set it up, but it will not have the same rights as the win application you run as your own user.
Try setting the folder to Full control for Everyone just to check that it works, and refine the permissions afterwards if that is the source of the problems.
Upvotes: 2