GreenRock Software Code Comment

April 9, 2008

Tidy Unformatted XML in Word

Filed under: New Posts, tips — greenrocksoftware @ 9:59 am




Note: Use the Special –> Manual Line Break to create the ^|. The keyboard characters map incorrectly.

March 20, 2008

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

Filed under: New Posts, tips — greenrocksoftware @ 3:48 am

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);
}
}

Blog at WordPress.com.