public void Contains() { var num = 5; var list = new SoftList <Person>(); for (int i = 1; i <= num; i++) { list.Add(new Person(i.ToString())); } ConsoleEx.WriteLine("\n> First collection..."); GC.Collect(); GC.WaitForPendingFinalizers(); Assert.AreEqual(num, list.Count); ConsoleEx.WriteLine("\n> Testing not the same reference..."); var obj = new Person("1"); var tmp = list.Contains(obj); Assert.IsFalse(tmp); ConsoleEx.WriteLine("\n> Testing the same reference..."); obj = list.Find(x => x.Name == "1"); Assert.IsNotNull(obj); obj = list[0]; tmp = list.Contains(obj); Assert.IsTrue(tmp); }
/// <summary> /// 读取程序列表 /// </summary> public void LoadSoftList() { Task.Factory.StartNew(() => { List <Soft> temp = new List <Soft>(); int index = 1; foreach (Process p in Process.GetProcesses(Environment.MachineName)) { //此进程主窗口句柄不为NULL if (p.MainWindowHandle != IntPtr.Zero) { Soft soft = new Soft { Handle = p.MainWindowHandle, Title = p.MainWindowTitle, Name = p.ProcessName, Index = index }; temp.Add(soft); index++; } } //委托UI线程 Execute.OnUIThread(() => { //将缓存中的进程列表加入显示列表集合中 temp.ForEach(p => SoftList.Add(p)); }); }); }
private void wMain_Load(object sender, EventArgs e) { for (int i = 1; i <= 9; i++) { ((Label)(this.Controls.Find("label" + i, true)[0])).Text = i + "、" + AppConfig.appConfig.getTempName(i + ""); } this.listView1.Columns.Add("进程名", listView1.Width - 5, HorizontalAlignment.Center); //一步添加 SoftList softList = AppConfig.appConfig.getSoftMonitoring(); listView1.BeginUpdate(); foreach (SoftBean soft in softList.softs) { ListViewItem lvi = new ListViewItem(); lvi.Text = soft.name; listView1.Items.Add(lvi); } listView1.EndUpdate(); string[] serialPortList = UsartManager.usartManager.getHostSerialPort(); comboBox1.Items.AddRange(serialPortList); comboBox1.SelectedIndex = 0; DataParser.parser.setUpdate(upStatusData); }
private void BtnAll_OnClick(object sender, RoutedEventArgs e) { SoftList list = new SoftList(); list.DataContext = new SoftListVM(vm.AppFiles); list.ShowDialog(); }
public void Performance() { Func <string, Action, double> executor = (message, action) => { ConsoleEx.WriteLine("\n> {0}", message); Stopwatch watch = new Stopwatch(); watch.Start(); action(); watch.Stop(); var secs = (double)watch.ElapsedMilliseconds / 1000; ConsoleEx.WriteLine("- Elapsed: {0} secs.", secs.ToString("#,###.0000")); return(secs); }; long count = 4 * 1000; string str = null; str = string.Format("Testing {0} Standard List...", count.ToString("#,###")); var std = executor(str, () => { var list = new List <Person>(); for (long i = 0; i < count; i++) { GC.Collect(); GC.WaitForPendingFinalizers(); var obj = new Person("James Bond"); list.Add(obj); } }); str = string.Format("Testing {0} Soft List...", count.ToString("#,###")); var neo = executor(str, () => { var list = new SoftList <Person>(); for (long i = 0; i < count; i++) { GC.Collect(); GC.WaitForPendingFinalizers(); var obj = new Person("James Bond"); list.Add(obj); } }); var dif = neo - std; var fct = neo / std; if (fct < 1) { fct = 1 / fct; } ConsoleEx.WriteLine("\n> Test - Standard = {0} => Factor: {1}", dif.ToString("#,###.0000"), fct.ToString("#,###.00")); }
public SoftList getSoftMonitoring() { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); if (config.AppSettings.Settings["soft"] == null) { return(new SoftList()); } string json = config.AppSettings.Settings["soft"].Value; SoftList softList = JsonConvert.DeserializeObject <SoftList>(json); return(softList); }
private void SoftMonitoring_Load(object sender, EventArgs e) { InitList(); this.listView2.Columns.Add("进程名", listView2.Width - 5, HorizontalAlignment.Center); //一步添加 softList = AppConfig.appConfig.getSoftMonitoring(); listView2.BeginUpdate(); foreach (SoftBean soft in softList.softs) { ListViewItem lvi = new ListViewItem(); lvi.Text = soft.name; listView2.Items.Add(lvi); } listView2.EndUpdate(); }
public void Expires_After_Next_GC() { var num = 5; var list = new SoftList <Person>(); for (int i = 1; i <= num; i++) { list.Add(new Person(i.ToString())); } ConsoleEx.WriteLine("\n> First collection..."); GC.Collect(); GC.WaitForPendingFinalizers(); Assert.AreEqual(num, list.Count); ConsoleEx.WriteLine("\n> Second collection..."); GC.Collect(); GC.WaitForPendingFinalizers(); Assert.AreEqual(0, list.Count); }
public void Survive_Many_Cycles() { var cycles = 2; var num = 5; var list = new SoftList <Person>() { GCCycles = cycles }; for (int i = 1; i <= num; i++) { list.Add(new Person(i.ToString())); } // Survive for the given number of cycles... for (int i = 0; i < cycles; i++) { GC.Collect(); GC.WaitForPendingFinalizers(); ConsoleEx.WriteLine("- Iteration: {0} ==> {1}", i, list); Assert.AreEqual(num, list.Count); } // Collected afterwards... var max = 10; ConsoleEx.WriteLine("\n> Testing for max {0} iterations...", max); for (int i = 0; i < max; i++) { GC.Collect(); GC.WaitForPendingFinalizers(); ConsoleEx.WriteLine("- Iteration: {0} ==> {1}", i, list); if (list.Count == 0) { break; } } Assert.AreEqual(0, list.Count); }
public void Survive_While_Used() { var num = 5; var list = new SoftList <Person>(); for (int i = 1; i <= num; i++) { list.Add(new Person(i.ToString())); } var max = 10; ConsoleEx.WriteLine("\n> Testing for max {0} iterations...", max); for (int i = 0; i < max; i++) { GC.Collect(); GC.WaitForPendingFinalizers(); ConsoleEx.WriteLine("- Iteration: {0} ==> {1}", i, list); var target = list[0]; // Capturing the target to prevent its collection... Assert.IsNotNull(target); Assert.IsTrue(list.Count >= 1); } Assert.IsTrue(list.Count >= 1); }
private void SelectVaultToolStripMenuItemClick(object sender, EventArgs e) { var v = new FrmVaults(); v.ShowDialog(this); Data = (SoftList)DeSerialization(typeof(SoftList), @"/" + Lists.Last); DisplayList(Data); }
private void FrmMainLoad(object sender, EventArgs e) { if (!Directory.Exists(Application.StartupPath + @"\images")) Directory.CreateDirectory(Application.StartupPath + @"\images"); // Lists = (SoftLists)DeSerialization(typeof(SoftLists), @"/soft.idx"); if (Lists == null) { Lists = new SoftLists(); var x = new SoftListInfo { Title = "Software", Vault = "soft.vault" }; Lists.Vaults.Add(x); Lists.Last = x.Vault; Serialization(typeof(SoftLists), @"/soft.idx", Lists); } Data = (SoftList)DeSerialization(typeof(SoftList), @"/" + Lists.Last); if (Data == null) { Data = new SoftList(); Serialization(typeof(SoftList), @"/" + Lists.Last, Data); } DisplayList(Data); _setings = (Options)DeSerialization(typeof(Options), @"/app.setings"); if (Setings == null) { _setings = new Options(); } Serialization(typeof(Options), @"/app.setings", Setings); if (Setings != null) lstSoftware.ListViewItemSorter = Setings.Order >= lstSoftware.Items.Count ? new ListViewItemComparer() : new ListViewItemComparer(Setings.Order); lstSoftware.Sort(); }
// ReSharper restore SuggestBaseTypeForParameter // ReSharper disable SuggestBaseTypeForParameter private void DisplayList(SoftList data) { lstSoftware.Items.Clear(); lstSoftware.OwnerDraw = true; lstSoftware.SuspendLayout(); ListViewItem x; for (int i = 0; i < data.Count; i++) { x = new ListViewItem(data[i].Title); x.SubItems.Add(data[i].Location); x.SubItems.Add(i.ToString()); lstSoftware.Items.Add(x); } lstSoftware.OwnerDraw = false; lstSoftware.ResumeLayout(); }
public void Run() { Ways wat = new Ways(); softList = new SoftList(); try { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Product"); int i = 0; foreach (ManagementObject queryObj in searcher.Get()) { i++; String idN = ""; String name = ""; String vend = ""; String instLoc = ""; String prodID = ""; String version = ""; try { idN = queryObj["IdentifyingNumber"].ToString(); } catch (Exception) { } try { name = queryObj["Name"].ToString(); } catch (Exception) { } try { vend = queryObj["Vendor"].ToString(); } catch (Exception) { } try { instLoc = queryObj["InstallLocation"].ToString(); } catch (Exception) { } try { prodID = queryObj["ProductID"].ToString(); } catch (Exception) { } try { version = queryObj["Version"].ToString(); } catch (Exception) { } if (name == "VMware Workstation" || name=="Microsoft Visual Studio Professional 2013") { Console.WriteLine(name+" " + version); } softList.addSoft(new Software(idN, name, vend, instLoc, prodID, version)); } } catch (ManagementException e) { MessageBox.Show("An error occurred while querying for WMI data: " + e.Message); } softList.firstTurn(); foreach (Software s in softList.getList()) { this.AddToListBoxSoftwares(s.toStringKey()); } softList.secondTurn(); foreach (Software s in softList.getList()) { this.AddToListBoxSoftwares(s.toStringKey()); } }