Home > C# Code Comments > Running a service as an application (or v.v)

Running a service as an application (or v.v)


public static void Main(string[] args)
{
//If ‘ApplicationMode’ argument was passed then run as a windows application otherwise run as a Windows service.
if (args.Length > 0)
{
foreach (string currentArg in args)
{
if (String.Compare(currentArg, “-applicationmode”, true, CultureInfo.InvariantCulture) == 0)
{
_runningAsService = false;
}
}
}

_exceptionHandler = new ExceptionHandler(_runningAsService, SR.ServiceMainName);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(_exceptionHandler.OnUnhandledException);

if (_runningAsService)
{
//Service
System.ServiceProcess.ServiceBase[] ServicesToRun = new System.ServiceProcess.ServiceBase[] { new DispatchService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
else
{
//Windows Application
System.Windows.Forms.Form applicationForm = new ApplicationModeForm();
System.Windows.Forms.Application.Run(applicationForm);
}
}

Advertisements
Categories: C# Code Comments
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: