Beispiel #1
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            InitLanguage();
            if (e.Args.Length > 0)
            {
                // This arg is used when start on boot. When user set false on "start on boot", the program still starts on boot but then stops immediately.
                if (e.Args[0] == "-startup")
                {
                    if (!Settings.Default.startOnBoot)
                    {
                        Shutdown();
                        return;
                    }
                }
                // These arguments is used when program restart. Will firstly show the window of detail of specific process.
                else if (e.Args.Length == 2 && e.Args[0] == "-processid")
                {
                    if (Int32.TryParse(e.Args[1], out int id))
                    {
                        ProcessDetailWindow w = new ProcessDetailWindow(id, null);
                        Dispatcher.InvokeAsync(new Action(() => { w.Show(); }));
                    }
                }
            }

            mutex = new Mutex(true, "USTC.Software.hanyizhao.NetSpeedMonitor", out bool createNew);

            // There is no instance until now.
            if (createNew)
            {
                captureManager = new CaptureManager(udMap);
                welcomeWindow  = new WelcomeWindow();
                welcomeWindow.Show();
                Thread t = new Thread(new ThreadStart(() => {
                    //如果用户按的足够快,先按了exit,那么会先执行Exit,后执行captureManager.InitAndStart() !!! This is a bug, but it will not trigger unless user is really really fast !!!.
                    if (!captureManager.InitAndStart())
                    {
                        Dispatcher.InvokeAsync(new Action(() => {
                            MessageBox.Show("WinPcap is one dependency of NetSpeedMonitor.\nYou can visit https://www.winpcap.org/ to install this software.\nAnd make sure WinPcap is properly installed on the local machine. \n\n[NetSpeedMonitor]");
                            Process.Start("https://www.winpcap.org/");
                            Shutdown();
                        }));
                    }
                    else
                    {
                        Dispatcher.InvokeAsync(new Action(() => {
                            InitViewAndNeedCloseResourcees();
                            welcomeWindow.ReduceAndClose(new Point(mainWindow.Left + mainWindow.Width / 2, mainWindow.Top + mainWindow.Height / 2));
                        }));
                    }
                }));
                t.Start();
            }
            else
            {
                Shutdown();
            }
        }
 private void DetailLabel_MouseDown(object sender, MouseButtonEventArgs e)
 {
     if (sender is Label label)
     {
         int row = Grid.GetRow(label);
         if (row >= 0 && row < localItems.Count)
         {
             int id = localItems[row].ProcessID;
             if (idMap.TryGetValue(id, out ProcessView process))
             {
                 ProcessDetailWindow win = new ProcessDetailWindow(process);
                 win.Show();
             }
             else
             {
                 ProcessDetailWindow win = new ProcessDetailWindow(id);
                 win.Show();
             }
         }
     }
 }