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

Convert Console App To Windows Service Question

How would I convert the following console app to a windows service??

using System;

using System.IO;

using FileProcessor;

namespace DirectoryMonitorConsole

{

/// <summary>

/// Summary description for Class1.

/// </summary>

public class DirectoryMonitorConsole

{

private File_Processor objFileProcessor;

/// <summary>

/// Used as a test application for the Directory Monitor Service

/// </summary>

[STAThread]

public static void Main()

{

// Define the directory to monitor

FileSystemWatcher watcher = new FileSystemWatcher();

watcher.Path = @"c:\FTPIN\PSIFL";

//watcher.Path = @"d:\FTPIN\PSIFL";

// Define what to monitor

watcher.NotifyFilter = NotifyFilters.DirectoryName | NotifyFilters.FileName;

// Define file filter

watcher.Filter = "*.*";// look for any new file

// Define event handlers

watcher.Created += new FileSystemEventHandler(OnChanged);

// Begin watching the directory

watcher.EnableRaisingEvents = true;

// Wait for the user to quit the program

Console.WriteLine(@"Press q to quit this program");

while(Console.Read()!='q');

}
/// <summary>

/// Event handler for a new file put into the directory that is being
monitored

/// </summary>

/// <param name="source"></param>

/// <param name="e"></param>

private static void OnChanged(object source, FileSystemEventArgs e)

{

Console.WriteLine("File: {0} {1}!", e.FullPath, e.ChangeType);

// Get the name of the new file

// Make a reference to a directory

DirectoryInfo di = new DirectoryInfo(@"c:\FTPIN\PSIFL");

//DirectoryInfo di = new DirectoryInfo(@"c:\FTPIN\PSIFL");

// Get a reference for each file in the directory

FileInfo[] fi = di.GetFiles();

string strFileName = fi[0].ToString();

fi = null;

di = null;

File_Processor objFileProcessor = new
FileProcessor.File_Processor(strFileName);

objFileProcessor = null;

}

}

}
Nov 16 '05 #1
1 3848
Just create a new project, and add the code to create the FileSystemWatcher
in the OnLoad event.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jack David" <JD****@NordisDirect.com> wrote in message
news:Oh**************@TK2MSFTNGP11.phx.gbl...
How would I convert the following console app to a windows service??

using System;

using System.IO;

using FileProcessor;

namespace DirectoryMonitorConsole

{

/// <summary>

/// Summary description for Class1.

/// </summary>

public class DirectoryMonitorConsole

{

private File_Processor objFileProcessor;

/// <summary>

/// Used as a test application for the Directory Monitor Service

/// </summary>

[STAThread]

public static void Main()

{

// Define the directory to monitor

FileSystemWatcher watcher = new FileSystemWatcher();

watcher.Path = @"c:\FTPIN\PSIFL";

//watcher.Path = @"d:\FTPIN\PSIFL";

// Define what to monitor

watcher.NotifyFilter = NotifyFilters.DirectoryName | NotifyFilters.FileName;
// Define file filter

watcher.Filter = "*.*";// look for any new file

// Define event handlers

watcher.Created += new FileSystemEventHandler(OnChanged);

// Begin watching the directory

watcher.EnableRaisingEvents = true;

// Wait for the user to quit the program

Console.WriteLine(@"Press q to quit this program");

while(Console.Read()!='q');

}
/// <summary>

/// Event handler for a new file put into the directory that is being
monitored

/// </summary>

/// <param name="source"></param>

/// <param name="e"></param>

private static void OnChanged(object source, FileSystemEventArgs e)

{

Console.WriteLine("File: {0} {1}!", e.FullPath, e.ChangeType);

// Get the name of the new file

// Make a reference to a directory

DirectoryInfo di = new DirectoryInfo(@"c:\FTPIN\PSIFL");

//DirectoryInfo di = new DirectoryInfo(@"c:\FTPIN\PSIFL");

// Get a reference for each file in the directory

FileInfo[] fi = di.GetFiles();

string strFileName = fi[0].ToString();

fi = null;

di = null;

File_Processor objFileProcessor = new
FileProcessor.File_Processor(strFileName);

objFileProcessor = null;

}

}

}

Nov 16 '05 #2

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

Similar topics

1
by: Shawn Buchanan-Cook | last post by:
Hello, I have created a windows service that executes a application (that has a user interface), and therefore I have the "Allow service to interact with desktop" checked... I have found that...
4
by: Nathan Kovac | last post by:
I have a windows service project created with a timer that fires an event over and over. I created an installer & the service appears to install correctly. When I try to start the service I get a...
3
by: Nathan Kovac | last post by:
I have a feeling I am missing something simple, but I just can't find it. Perhaps someone can give me a lead on where to look. I will describe the issue then post my code to the web service. My...
1
by: vul | last post by:
I created Windows Service in VB.Net with the name MSFaxListener. It should listen Windows Fax Service events and update SQL Server database when fax job changes it's status. In order to do that in...
0
by: lcifers | last post by:
As mentioned in my earlier post regarding creating an application object from a Windows service, I have a Windows app that I'm migrating to a Windows service. This is the first time I have written...
4
by: ggillard | last post by:
Hi, I'm new to writing services and found it pretty easy using VB.NET. My service has an internal timer that fires every 3 seconds. Each time it fires it opens a SQL DB and looks for a...
4
by: Gordon | last post by:
Hi; I have developed a VB.net app in a module that queries a database, loads the data into several arrays and then loops through the array. It then compares time data stored in the array with...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.