private void changeEventBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { lock (_lockObject) { WorkEventArgs wea = (WorkEventArgs)e.Argument; if (wea.CurrentItem != null) { wea.CurrentItem.Text = wea.FileName; wea.CurrentItem.SubItems[1].Text = DateTime.Now.ToLongTimeString(); Int64 currCount = Convert.ToInt64(wea.CurrentItem.SubItems[2].Text.ToString()) + 1; wea.CurrentItem.SubItems[2].Text = currCount.ToString(); } else { ListViewItem mainItem = new ListViewItem(wea.FileName); mainItem.Tag = wea.EventType; mainItem.SubItems.Add(DateTime.Now.ToLongTimeString()); mainItem.SubItems.Add("1"); mainItem.SubItems.Add(wea.EventType); eventList.Items.Add(mainItem); } } }
private void HandleFileSystemWatcherUpdate() { WorkEventArgs doWorkEventObject = WorkEvents.Instance.GetEventObject(); if (doWorkEventObject != null) { string fileName = doWorkEventObject.FileName; if (CheckExclusions(Path.GetDirectoryName(fileName))) { string eventTypeString = doWorkEventObject.EventType; ListViewItem currItem = null; lock (eventList) { try { foreach (ListViewItem lvi in eventList.Items) { if (lvi.Text == fileName && lvi.Tag.ToString() == eventTypeString) { currItem = lvi; continue; } } } catch { } } WorkEventArgs wea = new WorkEventArgs(fileName, eventTypeString, currItem); // DoWorkEventArgs dw = new DoWorkEventArgs(wea); if (!changeEventBackgroundWorker.IsBusy) { changeEventBackgroundWorker.RunWorkerAsync(wea); } else { WorkEvents.Instance.Add(wea); } } } }
private void HandleFileSystemWatcherUpdate(EventType eventType, FileSystemEventArgs e) { string fileName = fileSystemWatcher.Path + e.Name; if (CheckExclusions(Path.GetDirectoryName(fileName))) { string eventTypeString = string.Empty; switch (eventType) { case EventType.Modified: { if (!checkModified.Checked) { return; } eventTypeString = "Modified"; break; } case EventType.Created: { if (!checkCreated.Checked) { return; } eventTypeString = "Created"; break; } case EventType.Deleted: { if (!checkDeleted.Checked) { return; } eventTypeString = "Deleted"; break; } case EventType.Renamed: { if (!checkRenamed.Checked) { return; } eventTypeString = "Renamed"; break; } } ListViewItem currItem = null; lock (eventList) { try { foreach (ListViewItem lvi in eventList.Items) { if (lvi.Text == fileName && lvi.Tag.ToString() == eventTypeString) { currItem = lvi; continue; } } } catch { } } WorkEventArgs wea = new WorkEventArgs(fileName, eventTypeString, currItem); // DoWorkEventArgs dw = new DoWorkEventArgs(wea); if (!changeEventBackgroundWorker.IsBusy) { changeEventBackgroundWorker.RunWorkerAsync(wea); } else { WorkEvents.Instance.Add(wea); } } }