473,698 Members | 2,574 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Attempting to fire two processes in a windows service

I have a service process that contains two services but only one of them ever
works properly. The background is I have two classes which are Individual()
and Mass() in the main service class and they both inherit ServiceBase. The
main Method is as follows:

static void Main()
{
System.ServiceP rocess.ServiceB ase[] ServicesToRun;

ServicesToRun = new System.ServiceP rocess.ServiceB ase[]
{
new MassService(),
new IndividualServi ce()
};

System.ServiceP rocess.ServiceB ase.Run(Service sToRun);
}

When I install the service and start it only the Mass service perfoms any
action and nothing occurs in the Individual service. I have tried creating
installers for each service and the same result occurs. I know the Individual
service works because if I reverse the order in Main() then Mass does not
work. Here is the code and both Mass and Indivudal are the same:

public class MassService : ServiceBase
{
private const string RETRY_MAX_TIME_ EXCEEDED = "The file \"{0}\" could not
be processed because a timeout occurred while waiting for the file to finish
uploading.";
private const string SUCCESS_EVENT_M SG = "The File \"{0}\" was successfully
procesed and has been deleted from the file system at \"{1}\"";
private const string FAILED_TO_ADD_T O_QUEUE = "The file \"{0}\" was not
added to the queue.";
private const string INBOUND_FILE_CO MPLETE_MSG = "The file \"{0}\" from IMDS
CDB was suucesfuly created at \"{1}\".";
private const string CLEANUP_EXCEPTI ON_MSG = "An error occured while
performing cleanup. The exception was: \"{0}\"";
private const string MASS_FSO_WATCHE R_EXCEPTION_MSG = "Error creating the
FileSystemWatch er object. The exception was: \"{0}\"";
private const string APP_CONFIG_EXCE PTION_MSG = "Error reading the
application configuration file. The exception was: \"{0}\"";
private const int RETRY_MAX_TIME = 3600000; // 1 hour
private const int RETRY_DELAY = 10000; // 10 seconds
private System.Diagnost ics.EventLog _eventLog = null;
private System.IO.FileS ystemWatcher _fileSystemWatc her = null;

private void InitializEventL og()
{
string _source = "MyApp Library Logging";
string _log = "MyApp";

if (!EventLog.Sour ceExists(_sourc e))
{
EventLog.Create EventSource(_so urce, _log);
}

_eventLog = new EventLog(); //Create Event Log
_eventLog.Log = _log; //Assign Event Log Name
_eventLog.Sourc e = _source; //Assign Event Source Name
}

private void IntializeFileSy stemWatcher()
{
string _massFileStore = string.Empty;
string _fileType = string.Empty;

try
{
_massFileStore = ConfigurationMa nager.AppSettin gs["MassXmlFileSto re"];
_fileType = ConfigurationMa nager.AppSettin gs["FileType"];
}
catch (Exception ex)
{
_eventLog.Write Entry(APP_CONFI G_EXCEPTION_MSG +
ex.Message.ToSt ring());
}

try
{
_fileSystemWatc her = new FileSystemWatch er(_massFileSto re, _fileType);
}
catch (Exception ex)
{
_eventLog.Write Entry(MASS_FSO_ WATCHER_EXCEPTI ON_MSG +
ex.Message.ToSt ring());
}

_fileSystemWatc her.EnableRaisi ngEvents = true; // Begin watching.
_fileSystemWatc her.IncludeSubd irectories = true; // Monitor Sub Folders
_fileSystemWatc her.NotifyFilte r = NotifyFilters.D irectoryName |
NotifyFilters.F ileName; // Apply filters

// Add event handlers for new XML files and deletion of existing XML
files.
_fileSystemWatc her.Created += new
FileSystemEvent Handler(OnXMLFi leCreated);
_fileSystemWatc her.Deleted += new
FileSystemEvent Handler(OnXMLFi leDeleted);
}

protected override void OnStart(string[] args)
{
InitializEventL og(); //Initialize Event Log
IntializeFileSy stemWatcher(); //Initialize File System Watcher
}

protected override void OnStop()
{
_fileSystemWatc her.Dispose();
_eventLog.Dispo se();
}

private void OnXMLFileDelete d(object source, FileSystemEvent Args args)
{
string _filename = args.FullPath;
DateTime _deletedAt = DateTime.Now;
_eventLog.Write Entry(String.Fo rmat(SUCCESS_EV ENT_MSG, _filename,
_deletedAt));
}

private void OnXMLFileCreate d(object source, FileSystemEvent Args args)
{
string _filename = args.FullPath;
DateTime _receivedAt = DateTime.Now;
_eventLog.Write Entry(String.Fo rmat(INBOUND_FI LE_COMPLETE_MSG , _filename,
_receivedAt));
}

private void FileCreated(obj ect sender, FileSystemEvent Args args)
{
string filename = args.FullPath;
DateTime receivedAt = DateTime.Now;
bool timedOut = false;
bool processed = false;

while (!(timedOut || processed))
{
if (FileUploadComp leted(filename) )
{
PassOffFileToOr acle(filename);
processed = true;
}
else
{
TimeSpan timeElapsed = DateTime.Now - receivedAt;

if (timeElapsed.To talMilliseconds RETRY_MAX_TIME)
{
timedOut = true;
}
else
{
Thread.Sleep(RE TRY_DELAY);
}
}
}

if (timedOut)
{
_eventLog.Write Entry(String.Fo rmat(RETRY_MAX_ TIME_EXCEEDED,
filename));
}
}

private bool FileUploadCompl eted(string filename)
{
try
{
using (FileStream inputStream = File.Open(filen ame, FileMode.Open,
FileAccess.Read ,
FileShare.None) )
{
return true;
}
}
catch (IOException)
{
return false;
}
}

private void PassOffFileToOr acle(string fileName)
{
// Add the file to the queue
FileQueue _queue = new FileQueue();
_queue.AddFileT oQueue(fileName );

if (!_queue.AddFil eToQueue(fileNa me))
try

{
_queue.GetAndRe moveTopMostFile Name();
// Oracle DAL Layer here
}
catch (Exception)
{
_eventLog.Write Entry(String.Fo rmat(FAILED_TO_ ADD_TO_QUEUE,
fileName));
}
}

private void CleanUpFile(str ing fileName)
{
string _massFileStore = string.Empty;

try
{
_massFileStore = ConfigurationMa nager.AppSettin gs["MassXmlFileSto re"];
System.IO.File. Delete(_massFil eStore + @"\" + fileName);
}
catch (Exception ex)
{
_eventLog.Write Entry(CLEANUP_E XCEPTION_MSG + ex.Message.ToSt ring());
}
}
}

I have created one installer and the services panel shows both and I can
start both but nothing is occuruing when it comes to the Individual service
but the Mass service works perfectly.

Any ideas why both services are not working?
Oct 15 '06 #1
2 1759
Hi,

Which version of .NET framework are you using?

I've just tested in .NET 2.0 and Visual Studio 2005 that hosting multiple
services in one process works: each service can start or stop
independently. I can send the test project to you if you're interested.

Also, please note: when passing multiple services to ServiceBase.Run (),
this means the services will run within in the same process.

You mentioned that you wanted to "fire two processes in a windows service",
I'm not quite sure about this, would you please telling me more? Thank you.

Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 16 '06 #2
I am using .NET 2.0.

I created one projct and I added two services and two installers within this
project. While both services showed up and I could start them only one ever
performed any work. I have corrected this today but I only have one service
and one installer and it works fine but I am not positive this is the best
method as I would actually prefer two services.

I can post these code changes if you want to see first hand what I have
done, just let me know if you want to see these changes. I would be willing
to guess you note about multiple services is where my problem resides.

In the meantime I would very much like to see your test project.

"Walter Wang [MSFT]" wrote:
Hi,

Which version of .NET framework are you using?

I've just tested in .NET 2.0 and Visual Studio 2005 that hosting multiple
services in one process works: each service can start or stop
independently. I can send the test project to you if you're interested.

Also, please note: when passing multiple services to ServiceBase.Run (),
this means the services will run within in the same process.

You mentioned that you wanted to "fire two processes in a windows service",
I'm not quite sure about this, would you please telling me more? Thank you.

Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 16 '06 #3

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

Similar topics

3
1619
by: Prabhu Shastry | last post by:
Hello group, I have a Windows Service and an application (C#). Both processes need access to a single dataset object (created and modified by the service and application will only read the dataset). I thought this was possible with ..Net remoting, but not able to figure out a way to make this possible. Does anyone know if it's possible to achieve this? Thanks, -Prabhu
2
5156
by: Besta | last post by:
Hello all, I am having trouble creating a windows service with a timer. Everything seems to go ok but the elapsed event does not fire.Can anyone shed any light on this, may be something simple as I am new to this. Full code below : using System; using System.Collections; using System.ComponentModel;
6
1363
by: Mark Nijhof | last post by:
Hi, A quicke summarize: I made a windows form that can set up a socket connection. It also has events that fire when data arives. Now I am using this form in a hidden way inside other code (was the only way I could get the threading to work for the client without the client needing to test for thread save stuff) It works in several programs (perfectly), but in a Windows Services it doesn't fire the event. I used debug lines to check...
2
1860
by: James Coe | last post by:
ARGH! Any ideas why this might be happening? The code I'm using comes straight from the example in the VB.NET Help System. All I did was tweak the name= stuff to match my application. Server Error in '/ImageMaker' Application. ---------------------------------------------------------------------------- ---- Configuration Error Description: An error occurred during the processing of a configuration file
4
7827
by: AN | last post by:
Greetings, We make an ASP.NET web application and we host it for our customers. We have provisioned hardware and hope to be able to service around 200 customers on this hardware. The web servers are in a stateless farm and have 2 GB of RAM. We are using ASP.NET 1.1 when using a dedicated application pool for each virtual directory. Each customer gets their own virtual directory and copy of the ASP.NET dll in their bin folder, which...
5
3718
by: Simon Hart | last post by:
Does anyone know the standard code access permission to be able to manipulate a process using the Process class? Thanks Simon.
5
4197
by: Stephen Barrett | last post by:
I have read many threads related to async fire and forget type calls, but none have addressed my particular problem. I have a webpage that instantiates a BL object and makes a method call. The BL object method actually sets up a delegate and calls a private method asynchronously and immediately returns back to the web page. The problem I am having is that the async call never happens. I added a quick logging call immediately as the...
5
1810
by: Andy Baker | last post by:
Our VB.NET 2003 application requires several processes to run overnight. I have written a program to perform these processes with a simple user interface to allow the user to switch various options on/off, and using the code from VB.NET programmer's cookbook (NotifyIcon) have it running in the system tray. When windows xp is started, the overnight routines program starts, and the icon appears in the system tray. I then use a timer to...
5
1552
by: amir | last post by:
Hello All, Just wanted to know if c# has a class which can handle communication between neighbour computers in same network so if i run a program on one computer it will be able to bring up processes and have all other properties of controling the state of that process through a service which is already running on windows... that is, without opening sockets ??? Thanks, Amir.
0
8610
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8902
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7740
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5862
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.