private void MainForm_Load(object sender, EventArgs e) { _beforeDialogSize = this.Size; //禁用关闭按钮 banCloseButton(); //根据检测机器,生成数据行列 InitListView(ini.IniReadValue("配置", "ChooseInstrument")); setAutoSize(dataListView); this.WindowState = FormWindowState.Minimized; this.ShowInTaskbar = false; this.notifyIcon1.Visible = true; //如果为东北角机器,则直接向kernal发送消息 if (ini.IniReadValue("配置", "ChooseInstrument").Equals(Utils.EASTERN_SOUTH)) { Message4Kernel msg4kernel = new Message4Kernel { id = Utils.EASTERN_SOUTH_ID, name = Utils.EASTERN_SOUTH, filePath = "", fileName = ini.IniReadValue("配置", "DataFolder"),//此处为要监控的文件名 fileType = ini.IniReadValue("配置", "MonitorFileType") }; //发送消息给kernel Utils.kernel.Notify_decode(msg4kernel); } else//否则监控文件夹新增*.mdb文件 { //开启监控线程 try { String folderPath = ini.IniReadValue("配置", "DataFolder"); String MonitorFileType = ini.IniReadValue("配置", "MonitorFileType"); startFileWatcher(MonitorFileType, folderPath); log.Debug("文件监控开启成功"); title = this.Text + "-文件监控开启成功"; } catch (Exception) { log.Debug("文件监控开启失败"); title = this.Text + "-文件监控开启失败"; } this.Text = this.title; } }
/** * filename: 过滤文件类型 * directoryName:目标文件夹 * function:开启文件监控 * 当文件发生变化时进行监控 **/ private void OnFileChanged(object sender, FileSystemEventArgs e) { logRichTextBox.Invoke((Action) delegate { logRichTextBox.AppendText("文件更改事件发生在" + e.FullPath + ";时间为" + DateTime.Now + "\n"); }); //定义消息 Message4Kernel msg4kernel = new Message4Kernel { id = long.Parse("10717"), name = ini.IniReadValue("配置", "ChooseInstrument"), filePath = Path.GetDirectoryName(e.FullPath), fileName = e.Name, fileType = ini.IniReadValue("配置", "MonitorFileType") }; //发送消息给kernel Utils.kernel.Notify_decode(msg4kernel); }