protected override void OnStartup(StartupEventArgs e) { //只允许运行一个实例 bool createdNew = false; FileInfo file = new FileInfo(Assembly.GetExecutingAssembly().Location); Environment.CurrentDirectory = file.DirectoryName; GlobalDataSingleton.Instance.ExeFileLocation = file.FullName; mutex = new Mutex(true, "{ximalaya-thirdpart}", out createdNew); if (e.Args != null && e.Args.Length > 0) { WriteToMappedFile(e.Args[0]); } else { WriteToMappedFile(string.Empty); } if (!createdNew) { Debug.WriteLine("**********************************************************************"); Debug.WriteLine("检测到已有一个喜马拉雅第三方客户端在运行,程序将关闭"); Debug.WriteLine("**********************************************************************"); Shutdown(0); return; } //设置调试输出 Debug.AutoFlush = true; Debug.Listeners.Add(new TextWriterTraceListener("ximalaya.log")); Debug.WriteLine(string.Empty); Debug.WriteLine("**********************************************************************"); Debug.WriteLine("喜马拉雅第三方客户端启动时间:" + DateTime.Now); Debug.WriteLine("**********************************************************************"); Debug.WriteLine(string.Empty); Exit += new ExitEventHandler((sender, e1) => { mutex.Close(); mutex = null; Debug.WriteLine(DateTime.Now.ToShortDateString() + " 程序结束,返回代码为" + e1.ApplicationExitCode); }); System.Windows.Media.RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly; /* 这句话可以使Global User Interface这个默认的组合字体按当前系统的区域信息选择合适的字形。 * 只对FrameworkElement有效。对于FlowDocument,由于是从FrameworkContentElement继承, * 而且FrameworkContentElement.LanguageProperty.OverrideMetadata()无法再次执行, * 目前我知道的最好的办法是在使用了FlowDocument的XAML的根元素上加上xml:lang="zh-CN", * 这样就能强制Global User Interface在FlowDocument上使用大陆的字形。 * */ FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.Name))); base.OnStartup(e); new MyBootstrapper().Run(); }
public void Dispose() { while (eventHandlerQueue.Count > 0) { ExitEventHandler handler = eventHandlerQueue.Dequeue(); handler(); } }
public Client() { _currentDomainOnUnhandledExceptionEventHandler = (sender, args) => CurrentDomainOnUnhandledExceptionEventHandler(sender, args); _dispatcherOnUnhandledExceptionEventHandler = (sender, args) => DispatcherOnUnhandledExceptionEventHandler(sender, args); _taskSchedulerOnUnobservedTaskExceptionEventHandler = (sender, args) => TaskSchedulerOnUnobservedTaskExceptionEventHandler(sender, args); _applicationExitEventHandler = (sender, args) => ApplicationExitEventHandler(sender, args); _mainWindowClosedEventHandler = (sender, args) => MainWindowClosedEventHandler(sender, args); _logger = LogHelper.TryGetLogger(); }
void OnAppStartup(object sender, StartupEventArgs e) { string serverDirectory = ForgeServer.Properties.Settings.Default.ServerDirectory; if (serverDirectory == null || serverDirectory == "") { SetupDirectory(); } Program = new Program(); Program.SetupServer(); Current.Properties.Add("program", Program); Exit += new ExitEventHandler(Program.OnProgramExit); }
public static void Main(string[] args) { Console.Title = "Tabula Rasa Auth Server"; _handler += new ExitEventHandler(Handler); SetConsoleCtrlHandler(_handler, true); login = new TRE.AuthenticationService.LoginServer(); login.Initialize(); deadLock = new DeadlockDetector(); if (!login.Start()) { Logger.WriteLog("Unable to start the server!", Logger.LogType.Error); System.Threading.Thread.Sleep(5000); return; } Process.GetCurrentProcess().WaitForExit(); }
App() { taskArray[0] = Task.Run( () => { m_Runtime = new Composer.Bridge.ComposerRuntime(); }); taskArray[1] = Task.Run(() => { m_Definitiion = ComposerJobDefinitionFactory.CreateFromFile("composer_gui.json"); //m_definition = ComposerJobDefinitionFactory.CreateFromFile("composer_gui.json"); //var d = new ComposerJobDefinition(@"c:\", @"d:\", @"e:\"); //ComposerJobDefinitionFactory.WriteToFile("composer_gui.json", d); } ); Startup += new StartupEventHandler(this.ApplicationStartupHandler); Exit += new ExitEventHandler(this.ApplicationExitHandler); }
protected override void OnStartup(System.Windows.StartupEventArgs e) { DispatcherUnhandledException += Application_DispatcherUnhandledException; // Call the OnStartup event on our base class base.OnStartup(e); var v = this.GetType().Assembly.GetName().Version; string preproduction = " ?"; if (v.Build == 0) { preproduction = ""; } else if (v.Build % 2 != 0) { preproduction = " αlpha" + (v.Build + 1) / 2 + " (rev." + v.Revision + ")"; } else if (v.Build % 2 == 0) { preproduction = " βeta" + v.Build / 2 + " (rev." + v.Revision + ")"; } this.Properties["Version"] = string.Format("v{0}.{1}{2}", v.Major, v.Minor, preproduction); this.Properties["VersionShort"] = string.Format("v{0}.{1}", v.Major, v.Minor); Exit += new ExitEventHandler(App_Exit); Thread preloader = new Thread(PreloadAssemblies); preloader.IsBackground = true; preloader.Priority = ThreadPriority.BelowNormal; preloader.Start(); this.Resources = Application.LoadComponent(new Uri("App.xaml", UriKind.RelativeOrAbsolute)) as ResourceDictionary; var w = new Window1(); ServiceLocator.RegisterService <IMainView>(w); var dlgsrv = new AppDialogService(); ServiceLocator.RegisterService <IDialogService>(dlgsrv); ServiceLocator.RegisterService <IMainWindow>(w); var vm = new Main { Themes = new ObservableCollection <ThemeInfo>(StyleLoader.GetAllStyles()) }; w.DataContext = vm; ServiceLocator.RegisterOverrideService <IKeyboardHandler>((IKeyboardHandler)vm); ServiceLocator.RegisterOverrideService <IActionExecutor>((IActionExecutor)vm); this.Resources.BeginInit(); var sl = new StyleLoader(Resources); var startTheme = new ThemeInfo { Path = "default" }; startTheme = sl.LoadStyle(startTheme); StyleLoader.CurrentStyleFolder = startTheme.Path; vm.CurrentTheme = vm.Themes.FirstOrDefault(t => t.Path == startTheme.Path); //this.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/Themes/default/style.xaml", UriKind.RelativeOrAbsolute)) as ResourceDictionary); this.Resources.EndInit(); sl.PerformInit = true; var b = new System.Windows.Controls.Button(); ServiceLocator.RegisterService <IStyleLoader>(sl); ServiceLocator.RegisterService <IFramePictureProvider>(w); ServiceLocator.RegisterService <IInputTeller>(w); ServiceLocator.RegisterService <IPlateProcessor>(vm); ServiceLocator.RegisterService <ISettings>(vm); //sl.LoadStyle("default"); string[] args = Environment.GetCommandLineArgs(); if (args.Length > 1) { (MainWindow as Window1).StartupFile = args[1]; } InterceptKeys.Start((MainWindow as Window1)); w.Show(); }
public App() { //只允许运行一个实例 bool createdNew = false; mutex = new Mutex(true, "{DBFE3F28-BA77-4FF6-9EBF-4FED90151A3E}", out createdNew); if (!createdNew) { Channel channel = Channel.FromCommandLineArgs(System.Environment.GetCommandLineArgs().ToList()); try { if (channel != null) { WriteStringToMappedFile(channel.ToCommandLineArgs()); } else { WriteStringToMappedFile("-show"); } } catch { } Debug.WriteLine("检测到已有一个豆瓣电台在运行,程序将关闭"); Shutdown(0); return; } //设置调试输出 Debug.AutoFlush = true; Debug.Listeners.Add(new TextWriterTraceListener("DoubanFM.log")); Debug.WriteLine(string.Empty); Debug.WriteLine("**********************************************************************"); Debug.WriteLine("豆瓣电台启动时间:" + App.GetPreciseTime(DateTime.Now)); Debug.WriteLine("**********************************************************************"); Debug.WriteLine(string.Empty); //出现未处理的异常时,弹出错误报告窗口,让用户发送错误报告 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((sender, e) => { if (mutex != null) { mutex.Close(); mutex = null; } if (exceptionObject == null) { exceptionObject = e.ExceptionObject; Debug.WriteLine("**********************************************************************"); Debug.WriteLine("豆瓣电台出现错误:" + App.GetPreciseTime(DateTime.Now)); Debug.WriteLine("**********************************************************************"); try { StringBuilder sb = new StringBuilder(); sb.AppendLine(DateTime.Now.ToString()); sb.AppendLine(ExceptionWindow.GetSystemInformation()); sb.AppendLine(ExceptionWindow.GetExceptionMessage(exceptionObject)); string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"K.F.Storm\豆瓣电台\error.log"); string directory = Path.GetDirectoryName(path); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } File.WriteAllText(path, sb.ToString()); DeleteSettingsIfEmergant(); } catch { } Dispatcher.Invoke(new Action(() => { try { SaveSettings(); var mainWindow = MainWindow as DoubanFMWindow; if (mainWindow != null) { if (mainWindow.NotifyIcon != null) mainWindow.NotifyIcon.Dispose(); } var window = new ExceptionWindow(); window.ExceptionObject = exceptionObject; window.ShowDialog(); Process.GetCurrentProcess().Kill(); } catch { SendReport(); } })); } else { DeleteSettingsIfEmergant(); SendReport(); } }); Exit += new ExitEventHandler((sender, e) => { if (mutex != null) { mutex.Close(); mutex = null; } Debug.WriteLine(App.GetPreciseTime(DateTime.Now) + " 程序结束,返回代码为" + e.ApplicationExitCode); }); InitializeComponent(); var player = FindResource("Player") as Player; if (player.Settings.CultureInfo != null) { Thread.CurrentThread.CurrentCulture = player.Settings.CultureInfo; Thread.CurrentThread.CurrentUICulture = player.Settings.CultureInfo; } //System.Windows.Media.RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly; /* 这句话可以使Global User Interface这个默认的组合字体按当前系统的区域信息选择合适的字形。 * 只对FrameworkElement有效。对于FlowDocument,由于是从FrameworkContentElement继承, * 而且FrameworkContentElement.LanguageProperty.OverrideMetadata()无法再次执行, * 目前我知道的最好的办法是在使用了FlowDocument的XAML的根元素上加上xml:lang="zh-CN", * 这样就能强制Global User Interface在FlowDocument上使用大陆的字形。 * */ FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.Name))); }
public App() { Startup += new StartupEventHandler(App_Startup); Exit += new ExitEventHandler(App_Exit); }
public App() { //只允许运行一个实例 bool createdNew = false; mutex = new Mutex(true, "{DBFE3F28-BA77-4FF6-9EBF-4FED90151A3E}", out createdNew); if (!createdNew) { Channel channel = Channel.FromCommandLineArgs(System.Environment.GetCommandLineArgs().ToList()); try { if (channel != null) { WriteStringToMappedFile(channel.ToCommandLineArgs()); } else { WriteStringToMappedFile("-show"); } } catch { } Debug.WriteLine("检测到已有一个豆瓣电台在运行,程序将关闭"); Shutdown(0); return; } //设置调试输出 Debug.AutoFlush = true; Debug.Listeners.Add(new TextWriterTraceListener("DoubanFM.log")); Debug.WriteLine(string.Empty); Debug.WriteLine("**********************************************************************"); Debug.WriteLine("豆瓣电台启动时间:" + App.GetPreciseTime(DateTime.Now)); Debug.WriteLine("**********************************************************************"); Debug.WriteLine(string.Empty); //出现未处理的异常时,弹出错误报告窗口,让用户发送错误报告 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((sender, e) => { if (mutex != null) { mutex.Close(); mutex = null; } if (exceptionObject == null) { exceptionObject = e.ExceptionObject; Debug.WriteLine("**********************************************************************"); Debug.WriteLine("豆瓣电台出现错误:" + App.GetPreciseTime(DateTime.Now)); Debug.WriteLine("**********************************************************************"); Debug.WriteLine(e.ExceptionObject.ToString()); try { StringBuilder sb = new StringBuilder(); sb.AppendLine(DateTime.Now.ToString()); sb.AppendLine(ExceptionWindow.GetSystemInformation()); sb.AppendLine(ExceptionWindow.GetExceptionMessage(exceptionObject)); string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"K.F.Storm\豆瓣电台\error.log"); string directory = Path.GetDirectoryName(path); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } File.WriteAllText(path, sb.ToString()); DeleteSettingsIfEmergant(); } catch { } Dispatcher.Invoke(new Action(() => { try { SaveSettings(); var mainWindow = MainWindow as DoubanFMWindow; if (mainWindow != null) { if (mainWindow.NotifyIcon != null) { mainWindow.NotifyIcon.Dispose(); } } var window = new ExceptionWindow(); window.ExceptionObject = exceptionObject; window.ShowDialog(); Process.GetCurrentProcess().Kill(); } catch { SendReport(); } })); } else { DeleteSettingsIfEmergant(); SendReport(); } }); Exit += new ExitEventHandler((sender, e) => { if (mutex != null) { mutex.Close(); mutex = null; } Debug.WriteLine(App.GetPreciseTime(DateTime.Now) + " 程序结束,返回代码为" + e.ApplicationExitCode); }); InitializeComponent(); var player = FindResource("Player") as Player; if (player.Settings.CultureInfo != null) { Thread.CurrentThread.CurrentCulture = player.Settings.CultureInfo; Thread.CurrentThread.CurrentUICulture = player.Settings.CultureInfo; } //System.Windows.Media.RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly; /* 这句话可以使Global User Interface这个默认的组合字体按当前系统的区域信息选择合适的字形。 * 只对FrameworkElement有效。对于FlowDocument,由于是从FrameworkContentElement继承, * 而且FrameworkContentElement.LanguageProperty.OverrideMetadata()无法再次执行, * 目前我知道的最好的办法是在使用了FlowDocument的XAML的根元素上加上xml:lang="zh-CN", * 这样就能强制Global User Interface在FlowDocument上使用大陆的字形。 * */ FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.Name))); }
protected override void OnStartup(StartupEventArgs e) { /*if (!System.Diagnostics.Debugger.IsAttached) AppDomain.CurrentDomain.UnhandledException += delegate(object sender, UnhandledExceptionEventArgs args) { Exception ex = args.ExceptionObject as Exception; var wnd = new ErrorWindow(ex); wnd.ShowDialog(); ErrorLog.WriteError(ex, "Unhandled Exception main", false); if (ErrorLog.CheckandUpload()) MessageBox.Show("Uploaded error log."); }; AppDomain.CurrentDomain.ProcessExit += delegate(object sender, EventArgs ea) { if (ErrorLog.CheckandUpload()) MessageBox.Show("Uploaded error log."); }; Updates.PerformHouskeeping(); */ string proc = Process.GetCurrentProcess().ProcessName; Process[] processes = Process.GetProcessesByName(proc); if (processes.Length > 1) { HardShutDown(); return; } if (isOctgnRunning) { MessageBox.Show("You must shut down OCTGN BEFORE you run this program!"); HardShutDown(); return; } Exit += new ExitEventHandler(App_Exit); ochecker = new Thread(new ThreadStart(delegate() { int a = 0; while (a == 0) { Thread.Sleep(1000); if (isOctgnRunning) { try { App.Current.Dispatcher.Invoke ( System.Windows.Threading.DispatcherPriority.Normal, new Action ( delegate() { MainWindow.IsEnabled = false; } ) ); //App.Current.MainWindow.IsEnabled = false; MessageBox.Show("You must shut down OCTGN BEFORE you run this program!"); } catch { } } else { App.Current.Dispatcher.Invoke ( System.Windows.Threading.DispatcherPriority.Normal, new Action ( delegate() { if (!MainWindow.IsEnabled) MainWindow.IsEnabled = true; } ) ); } } } )); ochecker.Start(); GamesRepository = new Octgn.Data.GamesRepository(); Relationships = new List<Relationship>(); DebugWindow = new DebugWindow(); #if(DEBUG) DebugWindow.Show(); App.Current.MainWindow = MainWindow; #endif base.OnStartup(e); }
public void Enqueue(ExitEventHandler handler) { eventHandlerQueue.Enqueue(handler); }
public static void Attach() { ExitHandler += ExitEventAction; SetConsoleCtrlHandler(ExitHandler, true); }
public App() : base() { Exit += new ExitEventHandler(ExecuteExit); GlobalData current = GlobalData.Current; #if DEBUG current.NoUpdate = true; #endif CommandLineOptionProcessor processor = new CommandLineOptionProcessor(current); try { processor.ProcessOptions(Environment.GetCommandLineArgs()); } catch (OpenSAGEException ex) { System.Windows.MessageBox.Show(ex.Message, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit((int)ErrorCode.CommandLineVerification); } _instance = new ResidentInstance(); if (_instance.IsFirstInstance) { _instance.Initialize(); } else { System.Windows.MessageBox.Show("Only one instance can run at the same time.", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit((int)ErrorCode.MultiInstance); } RegistryKey regKey = Registry.CurrentUser.OpenSubKey(GlobalData.RegPathBase, true); if (regKey == null) { regKey = Registry.CurrentUser.CreateSubKey(GlobalData.RegPathBase); } object result = regKey.GetValue(GlobalData.RegValueInstallPath); if (result == null) { string installPath = Assembly.GetExecutingAssembly().Location; installPath = Path.GetDirectoryName(installPath); regKey.SetValue(GlobalData.RegValueInstallPath, installPath); current.InstallPath = installPath; } else { current.InstallPath = result as string; } result = regKey.GetValue(GlobalData.RegValueUserDataLeafName); if (result == null) { regKey.SetValue(GlobalData.RegValueUserDataLeafName, GlobalData.DefaultUserDataLeafName); current.UserDataLeafName = GlobalData.DefaultUserDataLeafName; } else { current.UserDataLeafName = result as string; } LanguageLoader.LoadLanguage(); if (current.UI) { StartupUri = new Uri("pack://application:,,,/UIScreen.xaml"); } else { StartupUri = new Uri("pack://application:,,,/SplashScreen.xaml"); } }
private static extern bool SetConsoleCtrlHandler(ExitEventHandler handler, bool add);
protected static void Initialize(ExitEventHandler handler) { ExitHandler += handler; NativeMethods.SetConsoleCtrlHandler(ExitHandler, true); }
public App() { //首先注册开始和退出事件 Startup += new StartupEventHandler(App_Startup); Exit += new ExitEventHandler(App_Exit); }
private void Salir(object sender, ExitEventHandler e) { partidaService.EliminarPartida(JugadorSingleton.GetJugador().Username); }
public void Enqueue(ExitEventHandler handler) { this.eventHandlerQueue.Enqueue(handler); }
public static extern Boolean SetConsoleCtrlHandler(ExitEventHandler handler, Boolean add);