4

デフォルトでは、マシンによって作成されたスクリプトによってファイルがローカル/サーバー パス フォルダーに保存されますが、ネットワークの問題により、両方のフォルダーが同期されません。これを処理するために、以下のコーディングのように FileSystemWatcher、DiffEngine、System.Timers、および PingService を使用して C# ウィンドウ サービス プログラムを作成しました。ローカル フォルダーの OnChange イベントを監視するには、サーバー パスと比較/コピーする前にサーバー IP を Ping して成功/失敗します。Ping が失敗すると、logtemp フォルダーに移動し、システム タイマーがこれを処理し、logtemp ファイルを再ダンプする前に Ping を再度実行します。

これにスレッドを使用する方法がわかりません。ping が失敗した場合、システム タイマー コードはどこにありますか?

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

1 に答える 1