I'm trying to create windows service application to capture screen. Previously i had problem of starting the service. Anyhow I'm able to solved it and now I'm having another problem. Now image is saving but it saves as a black screen. for this also there's lot of questions asked in SOF, but i couldn't able to solve my problem.
Here what i have tried so far:
public partial class ScreenCaptureService : ServiceBase
{
private static Bitmap bmpScreenshot;
//private static Graphics gfxScreenshot;
System.Timers.Timer timer = new System.Timers.Timer();
public ScreenCaptureService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
TraceService();
timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
timer.Interval = 60000;
timer.Enabled = true;
}
protected override void OnStop()
{
timer.Enabled = false;
TraceService();
}
private void TraceService()
{
Desktop userDesk = new Desktop();
userDesk.BeginInteraction();
string path = @"D:Screen";
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
string fileName = string.Format("SCR-{0:yyyy-MM-dd_hh-mm-ss-tt}.png", DateTime.Now);
string filePath = path + fileName;
bmpScreenshot = CaptureScreen.GetDesktopImage();
bmpScreenshot.Save(filePath, ImageFormat.Png);
userDesk.EndInteraction();
}
private void OnElapsedTime(object source, ElapsedEventArgs e)
{
TraceService();
}
}
in here i followed codes mentioned in Here and Here. but it don't works for me.
I'm using windows 7 pc. i saw several answers mentioned about the session 0 isolation feature
but i couldn't get proper solution from them.
EDIT
here this service runs as session 0
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…