Multi Threading FileSystemWatcher changes the local folder and the timer processes when the network is disconnected, and Ping is again in the Window service

By default, the Script file recorded by the machine saves the files in the Local / Server Path folder, but due to a network problem, both folders are not synchronized. I skipped the C # window maintenance program using FileSystemWatcher, DiffEngine, System.Timers and PingService, as shown below, to handle this. To monitor the local OnChange Event folder, the Ping IP address is successful or unsuccessful before comparing / copying to the server path, when the Ping Fail is sent to the logtemp folder, the system timer processes this and Ping again before deleting the logtemp files again.

I do not know how to use threads for this. Where should my system timer be when ping fails?

protected override void OnStart(string[] args) { //all watcher config here// watcher.Path = "path"; watcher.NotifyFilter = NotifyFilters.LastWrite; watcher.Filter = "filename_company-Pg1_Product*"; watcher.Changed += new FileSystemEventHandler(LogFileSystemChanges); watcher.EnableRaisingEvents = true;} private void LogFileSystemChanges(object sender, FileSystemEventArgs e) { FileInfo sourcepath = new FileInfo(e.FullPath); FileInfo destPath = new FileInfo(Path.Combine(dFile, e.Name)); FileInfo _tempPath = new FileInfo(Path.Combine(tempPath, e.Name)); if (PingService()) //PingService Bool Type....Ping Specific IP Before Compare/Copy { if (!destPath.Exists) { LogEvent(destPath + " DOES NOT EXIST!! "); CopyFunction.CopyFile(sourcepath, destPath, true, true); } else { if (BinaryDiff(sFile, Path.Combine(dFile, e.Name))) //DiffEngine If Source & Diff are Different is TRUE. { CopyFunction.CopyFile(sourcepath, destPath, true, true); } } string msg = string.Format("Filename {0} are {1} now at {2} ", _ e.Name, e.ChangeType, DateTime.Now.ToString()); LogEvent(msg); } else { CopyFunction.CopyFile(sourcepath, _tempPath, true, true); } } 
+4
source share
1 answer

Use NServiceBus (with what they call a saga)

His project is open source, which allows you to protect your code from cases when the network is disconnected.

Or are you just asking how to make a thread?

If yes, see the MSDN examples for creating threads.

0
source

Source: https://habr.com/ru/post/1442459/


All Articles