473,385 Members | 2,029 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,385 software developers and data experts.

Migrating Console App To Windows Service

I have created a small console app that creates a few custom objects - each
of which makes use of the System.IO.FileSystemWatcher class. Each object is
responsible for monitoring a different folder on the local machine.

Here is the P-Code for the current console app version
static void Main() {
// 1 - Read the app's config file to determine which folders to watch

// 2 - Instantiate instances of my custom watcher class - one instance per
folder watched (and set various properties of each object) - then add each
instance to a HybridDictionary.

// 3 - KEEP THIS APP RUNNING until I explicitly end it
Console.WriteLine("Press \'q\' to quit the sample.");
while(Console.Read()!='q');

} // END OF P-CODE

What do I do about step 3 when converting this console app to a Windows
Service? How do I ensure that the program will run until I explicitly shut
it down (i.e., I don't want it to execute from top to bottom and then exit
immediately - as the console app would do without the two lines listed above
in step 3).

Thanks!
Nov 16 '05 #1
1 1326
In article <ez**************@tk2msftngp13.phx.gbl>, A@B.COM says...
I have created a small console app that creates a few custom objects - each
of which makes use of the System.IO.FileSystemWatcher class. Each object is
responsible for monitoring a different folder on the local machine.

Here is the P-Code for the current console app version
static void Main() {
// 1 - Read the app's config file to determine which folders to watch

// 2 - Instantiate instances of my custom watcher class - one instance per
folder watched (and set various properties of each object) - then add each
instance to a HybridDictionary.

// 3 - KEEP THIS APP RUNNING until I explicitly end it
Console.WriteLine("Press \'q\' to quit the sample.");
while(Console.Read()!='q');

} // END OF P-CODE

What do I do about step 3 when converting this console app to a Windows
Service? How do I ensure that the program will run until I explicitly shut
it down (i.e., I don't want it to execute from top to bottom and then exit
immediately - as the console app would do without the two lines listed above
in step 3).


You could put each FileSystemWatcher in a separate thread and use the
ManualResetEvent along with the WaitAll method to pause the main thread
until the other threads have completed.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 16 '05 #2

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

Similar topics

3
by: jabailo | last post by:
I am running the following remoting server as a Console application, and I want to convert it to a Windows Service. static void Main(string args) {...
2
by: Chris | last post by:
Hi, Currently, I have a console application written in C# and an unmanaged legacy DLL written in VC++ 6.0. In the DLL's previous application, when an event occurs in the DLL, a windows message...
1
by: Clifton Griffin | last post by:
Ok, I have a proxy server written in c#. Because I'm maintaning two versions (a console application for debugging and a windows service for deployment) I got the console application working,...
6
by: Shai Levi | last post by:
Hi, I'm trying to migrate native c++ class to managed c++ class. The native class header definition looks as: class NativeClass { public: typedef void (CbFunc1)(int n,void* p);
1
by: Samuel R. Neff | last post by:
We're using a 3rd party C DLL in a project that we don't have source for. When we call the DLL from a console app everything works fine. However, when we call it from a Windows Service, the DLL...
3
by: JohnH | last post by:
Does any one now how to create a .net service thet when run from the command line with say a -D argument will run as a console app and be able to output to that console window. The same .exe would...
2
by: Chris Mullins | last post by:
For some reason the question, "Can I make an EXE that is both a Windows Service and a Console Application?" has come up quite a bit for me over the last few weeks. I've been doing this for...
5
by: Jon Davis | last post by:
Is there such a thing as a Windows standard for killing a console app that is monitored by a System.Diagnostics.Process object? I'm hosting several C# console apps in a C# Windows service and...
12
by: Dilip | last post by:
Hi All I have a server based C# console application. This application must hide its console window when its launched out on the field. So I dutifully P/Invoke'd FindWindow/ShowWindow...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.