public void run() { switch (e.Type) { case Models.FileChangeEvent.FileChangeType.ClientCreate: ClientCreate(); break; case Models.FileChangeEvent.FileChangeType.ClientChange: ClientChange(); break; case Models.FileChangeEvent.FileChangeType.ClientRename: ClientRename(); break; case Models.FileChangeEvent.FileChangeType.ClientRenameAndClientChange: ClientRename(); ClientChange(); break; case Models.FileChangeEvent.FileChangeType.ClientRenameAndServerChange: ClientRename(); ServerChange(); break; case Models.FileChangeEvent.FileChangeType.ClientDelete: ClientDelete(); break; case Models.FileChangeEvent.FileChangeType.ServerCreate: ServerCreate(); break; case Models.FileChangeEvent.FileChangeType.ServerChange: ServerChange(); break; case Models.FileChangeEvent.FileChangeType.ServerRename: ServerRename(); break; case Models.FileChangeEvent.FileChangeType.ServerRenameAndClientChange: ServerRename(); ClientChange(); break; case Models.FileChangeEvent.FileChangeType.ServerRenameAndServerChange: ServerRename(); ServerChange(); break; case Models.FileChangeEvent.FileChangeType.ServerDelete: ServerDelete(); break; } FileProcessing.Remove(e.ProcessingPath()); Util.Global.updater.ThreadEnd(); }
public Models.FileChangeEvent GetAnEvent() { lock (EventQueue) { if (EventQueue.Count != 0) { for (int i = 0; i < EventQueue.Count; ++i) { Models.FileChangeEvent e = EventQueue.ElementAt(i); if (!FileProcessing.isInProcessing(e.ProcessingPath())) { EventQueue.Remove(e); return(e); } } return(null); } else { Util.Global.manualResetEvent.Reset(); return(null); } } }
public FileUpdater() { ThreadCount = 0; UploaderThread = new Thread(new ThreadStart(() => { while (!stop) { if (ThreadCount < MaxThreadCount) { Models.FileChangeEvent e = Util.Global.FileUpdateQueue.GetAnEvent(); if (e != null) { FileProcessing.Add(e.ProcessingPath()); Interlocked.Increment(ref ThreadCount); FileUpdaterProcesser processer = new FileUpdaterProcesser(e); new Thread(new ThreadStart(processer.run)).Start(); } } Thread.Sleep(100); Util.Global.manualResetEvent.WaitOne(); } })); UploaderThread.Start(); }