473,564 Members | 2,758 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2444
To create Windows service, create a class that inherits from System.ServiceP rocess.ServiceB ase, System.ServiceP rocess

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.ServiceP rocess.ServiceB ase
{
private System.Threadin g.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.ServiceP rocess.ServiceB ase.Run(service );
}
}

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

public override void OnStart(string[] args)
{
timer = new Timer(new System.Threadin g.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>Call ed 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 (hasStuffToPrin t)
Print(stuffToPr int);
}

/// <summary>Call ed 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..jwaon line..com
-----------------------------------------------------------------------
"Chris" <Ch***@discussi ons.microsoft.c om> wrote in message news:DD******** *************** ***********@mic rosoft.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************ *************** *******@microso ft.com>,
Ch***@discussio ns.microsoft.co m 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.ServiceP rocess.ServiceB ase, System.ServiceP rocess

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.ServiceP rocess.ServiceB ase
{
private System.Threadin g.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.ServiceP rocess.ServiceB ase.Run(service );
}
}

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

public override void OnStart(string[] args)
{
timer = new Timer(new System.Threadin g.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>Call ed 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 (hasStuffToPrin t)
Print(stuffToPr int);
}

/// <summary>Call ed 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..jwaon line..com
-----------------------------------------------------------------------
"Chris" <Ch***@discussi ons.microsoft.c om> wrote in message news:DD******** *************** ***********@mic rosoft.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
1455
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 passing an ADO.NET DataSet Object as a parameter to the Web Method in Web Service Debugging using the Soap Extensions, clearly shows that the...
3
388
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 to email each new record to a specific person. This system will need to run automatically. I know I can do this using an exe com component using...
7
3920
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 the monitoring - but do I need to somehow involve another thread to allow the service to do other stuff as well, or is another thread created...
2
2027
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 you are developing on a machine that is behind a firewall and a proxy server has not been explicitly specified for Internet Explorer connections. You...
2
11797
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 application, DVD collection starter kit. How can I do? Any suggest? Thanks in advance. VAL
4
1897
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 another project that use windows form and it work. But when I implement my source code on my program that run as service on windows (I have change the...
0
5542
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 ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
1
6559
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 first service works fine. The second service appears to be registered correctly; yet I get the "System error 1083 has occurred." doing a "NET START...
2
1769
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
0
7665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.