示例#1
0
文件: App.cs 项目: radtek/Attache
        static void Main()
        {
            bool createdNew;
            var  mutexSecurity = new MutexSecurity();

            mutexSecurity.AddAccessRule(new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.FullControl, AccessControlType.Allow));
            using (var setupMutex = new Mutex(false, @"Global\JosipMedved_Attache", out createdNew, mutexSecurity)) {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                Medo.Application.UnhandledCatch.Attach();
                Medo.Application.UnhandledCatch.ThreadException += new EventHandler <ThreadExceptionEventArgs>(UnhandledCatch_ThreadException);

                bool runInteractive = (Medo.Application.Args.Current.ContainsKey("Interactive")) || IsRunningOnMono;

                if (runInteractive)   //start service threads

                {
                    if (!IsRunningOnMono)
                    {
                        Tray.Show();
                    }
                    AppServiceThread.Start();
                    Application.Run();
                    AppServiceThread.Stop();
                    if (!IsRunningOnMono)
                    {
                        Tray.Hide();
                    }
                }
                else if (Medo.Application.Args.Current.ContainsKey("Install"))
                {
                    ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
                    Environment.Exit(0);
                }
                else if (Medo.Application.Args.Current.ContainsKey("Uninstall"))
                {
                    try {
                        ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
                        Environment.Exit(0);
                    } catch (InstallException) { //no service with that name
                        Environment.Exit(-1);
                    }
                }
                else
                {
                    if (Environment.UserInteractive)   //show tray icon
                    {
                        Tray.Show();
                        Application.Run();
                        Tray.Hide();
                    }
                    else
                    {
                        ServiceBase.Run(new ServiceBase[] { AppService.Instance });
                    }
                }
            }
        }
示例#2
0
 protected override void OnStop()
 {
     AppServiceThread.Stop();
 }
示例#3
0
 protected override void OnStart(string[] args)
 {
     AppServiceThread.Start();
 }