Following code capture a screenshot of desktop in "Window Form Application"
But why this code can not capture screenshot in "Window Service Application"
protected override void OnStart(string[] args)
{
aTimer = new System.Timers.Timer(5000);
aTimer.Elapsed += new ElapsedEventHandler(CaptureScreen);
aTimer.Enabled = true;
}
public void CaptureScreen(object sender, EventArgs e)
{
bmp = new Bitmap(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
gr = Graphics.FromImage(bmp);
gr.CopyFromScreen(0, 0, 0, 0, new Size(bmp.Size.Width, bmp.Size.Height));
bmp.Save("D://screenshot.jpg");
}