private void Form1_Load(object sender, EventArgs e) { foreach (string name in names) { ToolStripMenuItem tsi = new ToolStripMenuItem(name); tsi.Click += ToolStripMenuItem_Click; contextMenuStrip1.Items.Add(tsi); } if (!File.Exists(strDownloadPath + "\\trainedImages.xml")) { return; } string xml = File.ReadAllText(strDownloadPath + "\\trainedImages.xml"); trainedFaces = (SeDes.ToObj(xml, trainedFaces) as List <trainedFace>); ThreadStart ts = new ThreadStart(fixFaces); progressBar1.Visible = true; IAsyncResult iar = ts.BeginInvoke((AsyncCallback) => { this.Invoke((MethodInvoker) delegate { progressBar1.Visible = false; }); }, null); }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { trainedFaces.ForEach(x => x.img = null); GC.Collect(); string xmlser = SeDes.ToXml(trainedFaces); File.WriteAllText(strDownloadPath + "\\trainedImages.xml", xmlser); }
private void trySave() { try { List <trainedFace> temptf = new List <trainedFace>(); foreach (trainedFace tf in trainedFaces) { temptf.Add(new trainedFace() { name = tf.name, path = tf.path, rect = tf.rect }); } string xmlser = SeDes.ToXml(temptf); File.WriteAllText(strDownloadPath + "\\trainedImages.xml", xmlser); } catch (Exception ex) { errorLabel.Text = ex.Message + "\n" + ex.StackTrace; } }