473,382 Members | 1,362 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Help with creating a windows service

Hi,
I need to create a windows service that will poll a database every 10 sec
and print processed orders to a printer. Where can I find info on this?

Thanks
Nov 22 '05 #1
3 2426
To create Windows service, create a class that inherits from System.ServiceProcess.ServiceBase, System.ServiceProcess

http://msdn.microsoft.com/library/de...classtopic.asp

For info on printing using .NET:

http://msdn.microsoft.com/library/de...asp?frame=true

Here's an example:

Start a timer when the service is started to perform some action every n milliseconds:

public class MyService : System.ServiceProcess.ServiceBase
{
private System.Threading.Timer timer;

/// <summary>Main entry point of the application. (*.exe)</summary>
public static void Main()
{
using (MyService service = new MyService())
{
// Blocks the thread until the serivce is stopped by a service controller. (You can go to services in administrative
tools, select your service, and click Stop)
System.ServiceProcess.ServiceBase.Run(service);
}
}

public MyService()
{
// tell the service control manager what operations can be performed on our service
CanShutdown = CanPauseAndContinue = CanHandlePowerEvent = false;
CanStop = true;
}

public override void OnStart(string[] args)
{
timer = new Timer(new System.Threading.TimerCallback(Poll), null, 0, 10000); // Poll every 10 seconds

// return immediately so the serivce controller knows that your service started successfully.
// You have 30 seconds to return from this method or the serivce will be stopped automatically by the SCM.
}

/// <summary>Called on a thread-pool thread at the specified interval. Do not process any asyncronous calls.</summary>
private void Poll(object state)
{
// do your polling here

if (hasStuffToPrint)
Print(stuffToPrint);
}

/// <summary>Called on a thread-pool thread. Do not process any asyncronous calls.</summary>
private void Print(object stuffToPrint)
{
// do your printing here.
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
if (timer != null)
timer.Dispose();
}
}
}
Good luck :)
--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Chris" <Ch***@discussions.microsoft.com> wrote in message news:DD**********************************@microsof t.com...
Hi,
I need to create a windows service that will poll a database every 10 sec
and print processed orders to a printer. Where can I find info on this?

Thanks

Nov 22 '05 #2
In article <DD**********************************@microsoft.co m>,
Ch***@discussions.microsoft.com says...
Hi,
I need to create a windows service that will poll a database every 10 sec
and print processed orders to a printer. Where can I find info on this?


"Writing a simple service application"
http://tinyurl.com/8mj8

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 22 '05 #3
Hi,
I want to be able to print the results from the database in an invoice
format, with all the columns and so on. I am not sure where to start from. Is
is possible to render each order in an html format (may be i can design the
invoice layout in html) and then send the print to printer without no dialog
boxes poping up.

"Dave" wrote:
To create Windows service, create a class that inherits from System.ServiceProcess.ServiceBase, System.ServiceProcess

http://msdn.microsoft.com/library/de...classtopic.asp

For info on printing using .NET:

http://msdn.microsoft.com/library/de...asp?frame=true

Here's an example:

Start a timer when the service is started to perform some action every n milliseconds:

public class MyService : System.ServiceProcess.ServiceBase
{
private System.Threading.Timer timer;

/// <summary>Main entry point of the application. (*.exe)</summary>
public static void Main()
{
using (MyService service = new MyService())
{
// Blocks the thread until the serivce is stopped by a service controller. (You can go to services in administrative
tools, select your service, and click Stop)
System.ServiceProcess.ServiceBase.Run(service);
}
}

public MyService()
{
// tell the service control manager what operations can be performed on our service
CanShutdown = CanPauseAndContinue = CanHandlePowerEvent = false;
CanStop = true;
}

public override void OnStart(string[] args)
{
timer = new Timer(new System.Threading.TimerCallback(Poll), null, 0, 10000); // Poll every 10 seconds

// return immediately so the serivce controller knows that your service started successfully.
// You have 30 seconds to return from this method or the serivce will be stopped automatically by the SCM.
}

/// <summary>Called on a thread-pool thread at the specified interval. Do not process any asyncronous calls.</summary>
private void Poll(object state)
{
// do your polling here

if (hasStuffToPrint)
Print(stuffToPrint);
}

/// <summary>Called on a thread-pool thread. Do not process any asyncronous calls.</summary>
private void Print(object stuffToPrint)
{
// do your printing here.
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
if (timer != null)
timer.Dispose();
}
}
}
Good luck :)
--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Chris" <Ch***@discussions.microsoft.com> wrote in message news:DD**********************************@microsof t.com...
Hi,
I need to create a windows service that will poll a database every 10 sec
and print processed orders to a printer. Where can I find info on this?

Thanks


Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Steven | last post by:
Hi all My problem is a little lengthy. But please help me. In my application, ADO.NET DataSet object is not getting constructed in the Web Service Web Method called by the Windows Application...
3
by: BobHutch | last post by:
I am trying to create a windows service using vb.net to read a sql table every half hour and copy all new records created within each half hour increment to another table. I also want to be able...
7
by: Simon Harvey | last post by:
Hi everyone, I need to make a service that monitors a directory for changes in the files contained within it. I have two questions: 1. I'm going to be using a FileSystemWatcher object to do...
2
by: Jeffrey Tate via DotNetMonster.com | last post by:
The error is: The proxy settings on this computer are not configured correctly for Web discovery. MSDN states that this is caused by: This error appears in the Add Web Reference dialog box if...
2
by: Val3 | last post by:
Hi all. I need to build dll(s) and windows services using VB .NET 2005 Express. When I make File/New project the windows contain only Windows application, Windows control library, Console...
4
by: Lemune | last post by:
Hello everyone. I'm using vb 2005. I'm creating program that run as service on windows. And in my program I need to use timer, so I'm using timer object from component. I try my source code on...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
1
by: =?Utf-8?B?cm9zczYxMw==?= | last post by:
I'm puzzled by an error message encountered while creating a Windows Service. In particular, I'm creating a second Windows Service within a Windows Service project, using Visual Studio 2005. The...
2
by: teejayem | last post by:
I am having problems creating a Windows Service using Visual Studio 2005. Code as follows:- Imports System.IO Imports System.Net.Mail
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.