EDN Admin
Well-known member
Hi all,
I have created the windows service project for desktop screen capture, but the service is not working.I dont know where i am going wrong.I have attach the sample project with this mail.
Please help.
Thanks
<pre class="prettyprint Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Diagnostics;
namespace TestServiceapplication
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1()
};
ServiceBase.Run(ServicesToRun);
}
}
}
Service1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
using System.Threading;
using System.IO;
namespace TestServiceapplication
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
public static long count;
public Bitmap CaptureWindow()
{
Thread.Sleep(1000);
Size boundsSize = Screen.PrimaryScreen.Bounds.Size;
PixelFormat gfxFormat = PixelFormat.Format32bppArgb;
Bitmap picture = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, gfxFormat);
Graphics graphics = Graphics.FromImage(picture);
graphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, boundsSize, CopyPixelOperation.SourceCopy);
DirectoryInfo dinfo = new DirectoryInfo(@"E:Sample Capture/WindowCapture/CaptureImage");
if (!dinfo.Exists)
{
dinfo.Create();
}
picture.Save("E:\Sample Capture/WindowCapture/CaptureImage/" + count++ + ".png", ImageFormat.Jpeg);
return picture;
}
protected override void OnStart(string[] args)
{
Service1 s = new Service1();
while (true)
{
s.CaptureWindow();
}
}
protected override void OnStop()
{
}
}
}
[/code]
<br/>
View the full article
I have created the windows service project for desktop screen capture, but the service is not working.I dont know where i am going wrong.I have attach the sample project with this mail.
Please help.
Thanks
<pre class="prettyprint Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Diagnostics;
namespace TestServiceapplication
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1()
};
ServiceBase.Run(ServicesToRun);
}
}
}
Service1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
using System.Threading;
using System.IO;
namespace TestServiceapplication
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
public static long count;
public Bitmap CaptureWindow()
{
Thread.Sleep(1000);
Size boundsSize = Screen.PrimaryScreen.Bounds.Size;
PixelFormat gfxFormat = PixelFormat.Format32bppArgb;
Bitmap picture = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, gfxFormat);
Graphics graphics = Graphics.FromImage(picture);
graphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, boundsSize, CopyPixelOperation.SourceCopy);
DirectoryInfo dinfo = new DirectoryInfo(@"E:Sample Capture/WindowCapture/CaptureImage");
if (!dinfo.Exists)
{
dinfo.Create();
}
picture.Save("E:\Sample Capture/WindowCapture/CaptureImage/" + count++ + ".png", ImageFormat.Jpeg);
return picture;
}
protected override void OnStart(string[] args)
{
Service1 s = new Service1();
while (true)
{
s.CaptureWindow();
}
}
protected override void OnStop()
{
}
}
}
[/code]
<br/>
View the full article