I have to capture a screenshot of the desktop after every second. This is running fine in the Winform application but after capturing the code in a Windows service it is not capturing screenshots. Why is not any idea doing this?
Here is the code
Public partial class screencapture service: servicebase {system. Tires Timer Timer = New System. Timer (); Public Screencake Service () {Initial Group (); This.timer.Interval = 1000; This.timer.Elapsed + = New System Timers.ElapsedEventHandler (timer_Elapsed); } Zero timer_executed (object sender, System.Timers.ElapsedEventArgs e) {CaptureScreen (); } Turn on Safe Override Zero (string [] ARG) {If EventLog.SourceExists (this .ServiceName, Environment.MachineName)} {EventLog.CreateEventSource (New Event Source DataData (This. ServiceName, Environment.MachineName)); } EventLog.WriteEntry (this.ServiceName, "OnStart Event has been called"); This.timer.Enabled = true; capture screen(); } Protected Override Zero Ontop () {EventLog.WriteEntry (This service name, "Ontop incident has been called"); This.timer.Enabled = false; } Fixed int calculation = 1; Private Zero Capture Screen () {bitmap prinsscreen = new bitmap (screen. Premiere screens.bounds, screen, premiumscreen.bound.height); Graphics Graphics = Graphics.Frame Image (Printscreen as Image); Graphics.CopyFromScreen (0, 0, 0, 0, printscreen.Size); PrincScreen Save (@ "C: \ Printscreen" + Count ++ + ".jpg", Image Format.jpg); EventLog.WriteEntry (This. ServiceName, "Screenshot Capture"); }}
Do you allow service to interact with "desktop" "Checked service property)?
No comments:
Post a Comment