protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException; DispatcherUnhandledException += Current_DispatcherUnhandledException; //System.Windows.Forms.NotifyIcon notifyIcon = new System.Windows.Forms.NotifyIcon(); try { string appName; try { appName = System.Windows.Application.ResourceAssembly.GetName().Name.ToString(); } catch { appName = "HIO"; } Pipe p = new Pipe(); if (p.Client()) { Shutdown(); return; } TMain.Instance = new TMain(); Task.Run(() => { p.Server(TMain.Instance); }); Task.Run(() => { UsbNotification un = new UsbNotification(); un.WatcherUSB(); }); HIOStaticValues.InitializeNotifyIcon(TMain.Instance); DispatcherTimer dtIcon = new DispatcherTimer(); dtIcon.Interval = TimeSpan.FromSeconds(3); dtIcon.Tick += DtIcon_Tick; dtIcon.Start(); if (e.Args.Length > 0 && e.Args[0] == "silent") { TMain.Instance.Start(true); } else { TMain.Instance.Start(false); } } finally { //Shutdown(); } }