0

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");
}
MD SHAHIDUL ISLAM
  • 14,325
  • 6
  • 82
  • 89
  • 1
    That is because a Windows Service Application doesn't have an initialized Desktop most of the time. So nothing to capture! – MrPaulch Jul 03 '15 at 16:28
  • Please see ["Should questions include “tags” in their titles?"](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles), where the consensus is "no, they should not"! –  Jul 03 '15 at 16:29

0 Answers0