April 9, 2008
March 20, 2008
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);
}
}
