static void Main(string[] arg) { AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += currentDomain_UnhandledException; //currentDomain.FirstChanceException += currentDomain_FirstChanceException; currentDomain.ProcessExit += currentDomain_ProcessExit; if (Environment.UserInteractive || Environment.OSVersion.Platform == PlatformID.MacOSX || Environment.OSVersion.Platform == PlatformID.Unix) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Instance = new WebDAVServerForm(arg); Application.Run(Instance); } else { Service = new WebDAVService(); var ServicesToRun = new ServiceBase[] { Service }; ServiceBase.Run(ServicesToRun); } }