private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { mutex.WaitOne(); ProcessConfig process = (ProcessConfig)AllProcess.SelectedItem; ObservableCollection <ProcessConfig> List = Copy(view.ProcessConfig.List); view.ProcessConfig.List.Clear(); if (process != null) { //if (ConvertToConfig((string)PrioritySelector.SelectedItem) == Config.Close) process.Priority = ConvertToConfig((string)PrioritySelector.SelectedItem); } foreach (var v in List) { view.ProcessConfig.List.Add(v); } mutex.ReleaseMutex(); }
public MainWindow() { if (!IsAdministrator()) { System.Windows.MessageBox.Show("Run application as Administrator!"); throw new Exception(); } ShowInTaskbar = true; InitializeComponent(); JArray array = JsonConvert.DeserializeObject <JArray>(File.ReadAllText("data.json")); foreach (var v in array) { ProcessConfig config = new ProcessConfig( v["Name"].ToString(), ConvertToConfig(v["Priority"].ToString()), v["System"].ToString() == "True" ? true : false ); view.ProcessConfig.List.Add(config); applyed = Copy(view.ProcessConfig.List); } this.notifier.MouseDown += new WinForms.MouseEventHandler(notifier_MouseDown); this.notifier.Icon = new System.Drawing.Icon("icon.ico"); this.notifier.Visible = true; DataContext = view; PrioritySelector.Items.Add("Close"); PrioritySelector.Items.Add("VeryLow"); PrioritySelector.Items.Add("Low"); PrioritySelector.Items.Add("Normal"); PrioritySelector.Items.Add("High"); PrioritySelector.Items.Add("VeryHigh"); PrioritySelector.Items.Add("RealTime"); thread = Task.Factory.StartNew(() => { while (true) { Thread.Sleep(10000); mutex.WaitOne(); foreach (var v in Process.GetProcesses()) { foreach (var conf in applyed) { if (v.ProcessName == conf.ProcessName) { if (conf.Priority == Config.Close) { v.Kill(); break; } if (conf.Priority == Config.Unknown) { break; } v.PriorityClass = ConvertToPriority(conf.Priority); break; } } } mutex.ReleaseMutex(); } }); }