private void button3_Click(object sender, EventArgs e) { this.button2.Enabled = true; FileMonitor.WatcherStop(); this.button3.Enabled = false; textBox1.AppendText("监控停止" + Environment.NewLine); }
private void button2_Click(object sender, EventArgs e) { try { #region 从配置文件读取信息 string path1 = null; string path2 = null; //string path = folderBrowserDialog1.SelectedPath; path1 = ConfigurationManager.AppSettings["path1"]; path2 = ConfigurationManager.AppSettings["path2"]; textBox2.Text = path1; textBox3.Text = path2; List <string> pathlist = new List <string>(); type = ConfigurationManager.AppSettings["type"].ToString(); if (string.IsNullOrEmpty(path1) && string.IsNullOrEmpty(path2)) { textBox1.AppendText("未设置监控文件夹" + Environment.NewLine); return; } else { if (!string.IsNullOrEmpty(path1)) { pathlist.Add(path1); } if (!string.IsNullOrEmpty(path2)) { pathlist.Add(path2); } } if (string.IsNullOrEmpty(type)) { textBox1.AppendText("未设置类型" + Environment.NewLine); } id = ConfigurationManager.AppSettings["id"]; foreach (string str in pathlist) { textBox1.AppendText("开始监控:" + str + Environment.NewLine); } #endregion FileMonitor.WatcherStart(pathlist, "*.*"); //启动监控 timer = new System.Threading.Timer(new TimerCallback(ThreadTimers), textBox1, 0, 5 * 1000); //每5秒钟调用一次 this.button2.Enabled = false; button3.Enabled = true; } catch (Exception ex) { textBox1.AppendText(ex.Message + Environment.NewLine); } }