private void Ok_Click(object sender, EventArgs e) { DialogResult = DialogResult.OK; switch (_mode) { default: case Mode.New: var domain = MemoryDomains.FirstOrDefault(d => d.Name == DomainDropDown.SelectedItem.ToString()); var address = AddressBox.ToLong() ?? 0; var notes = NotesBox.Text; var type = Watch.StringToDisplayType(DisplayTypeDropDown.SelectedItem.ToString()); var bigEndian = BigEndianCheckBox.Checked; switch (SizeDropDown.SelectedIndex) { case 0: Watches.Add(Watch.GenerateWatch(domain, address, WatchSize.Byte, type, bigEndian, notes)); break; case 1: Watches.Add(Watch.GenerateWatch(domain, address, WatchSize.Word, type, bigEndian, notes)); break; case 2: Watches.Add(Watch.GenerateWatch(domain, address, WatchSize.DWord, type, bigEndian, notes)); break; } break; case Mode.Edit: DoEdit(); break; case Mode.Duplicate: var tempWatchList = new List <Watch>(); tempWatchList.AddRange(Watches); Watches.Clear(); foreach (var watch in tempWatchList) { Watches.Add(Watch.GenerateWatch( watch.Domain, watch.Address, watch.Size, watch.Type, watch.BigEndian, watch.Notes)); } DoEdit(); break; } Close(); }
public void Test() { Watches.Clear(); for (int i = 0; i < Times; i++) { var sw = Stopwatch.StartNew(); for (int o = 0; o < Iterations; o++) { Function(); } sw.Stop(); Watches.Add(sw); } }
public void Load() { try { using (FileStream stream = File.OpenRead(saveFile)) { BinaryFormatter formatter = new BinaryFormatter(); Watches.Clear(); int watchCount = (int)formatter.Deserialize(stream); for (; watchCount > 0; watchCount--) { ProductMasterItem watch = (ProductMasterItem)formatter.Deserialize(stream); Watches.Add(watch); } } } catch (Exception e) { Console.WriteLine(e.Message); } }