2012-12-11 4 views
0

폴더에있는 모든 비디오 파일을 여러 주소로 전송하는 파일 감시자가있는 양식이 있습니다. 스레드에서 각 전송을 수행 할 수 있도록 여러 파일을 추가 할 때 최상의 옵션이 무엇입니까?FileWatcher를 사용하여 다른 스레드에서 파일을 전송하는 방법

DockingBarTransferEntities context = new DockingBarTransferEntities(); 

private void fileSystemWatcher1_Changed(object sender, System.IO.FileSystemEventArgs e) 
     { 
      IEnumerable<Diretorios> directories = context.Diretorios.ToList();    

      foreach (var destino in directories) 
      { 
       try 
       { 
        Transfere(e.FullPath,Path.GetFileName(e.FullPath),destino); 

       } 
       catch (Exception ex) 
       { 
        textBox1.Text += "Error: " + ex.Message; 
       } 
      } 
     } 

     public void Transfere(string fullPath, string name, Diretorios diretorio) 
     {   
      try 
      { 
       if (Directory.Exists(diretorio.Caminho)) 
       { 
        string fileName = Path.GetFileName(fullPath); 
        fileName = String.Format("{0}\\{1}", diretorio.Caminho, fileName); 

        FileInfo arquivo = new FileInfo(fullPath); 

        arquivo.CopyTo(fileName, true);     

       } 
      } 
      catch (Exception ex) 
      { 

      } 
     } 
+0

어떤 .NET 버전을 사용하고 있습니까? –

+0

. 실행 응용 프로그램 용 .NET Framework 4.0 및 Windows Server 2008 R2 –

답변

1

이이만큼 간단해야한다 : 여기 내 코드의 예 대신 직접 Transfere를 호출

Task.Factory.StartNew(() => Transfere(e.FullPath, Path.GetFileName(e.FullPath), destino)); 

.

+0

도움 주셔서 감사합니다! –

관련 문제