说下有问题的程序,首先建立一个FileSystemWatcher,监控目录是否有新的文件到达,如果到达了就线程池分配一个线程来读取文件,然后进行后续处理,思路很简单,代码如下:

readonly FileSystemWatcher _watcher;
   2:  
string path)
   4: {           
new FileSystemWatcher
   6:                   {
   7:                       Path = path,
   8:                       Filter = Constants.Configuration.ExcelFilter,
   9:                       NotifyFilter = NotifyFilters.FileName |
  10:                                      NotifyFilters.LastWrite |
  11:                                      NotifyFilters.CreationTime
  12:                   };
  13:  
  14:     _watcher.Created += OnNewFileComesin;
true;
  16: }
  17:  
object sender, FileSystemEventArgs e)
  19: {
  20:     Task.Factory.StartNew(() =>
  21:               {   
return ReadFile(e.FullPath);
  23:               })
  24:               .ContinueWith( 
//....
  26:                );
  27: }
  28:  
string filePath)
  30: {
new StreamReader(fullPath))
  32:    {
//...
return data;
  35:    }
  36: }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-16
  • 2021-08-11
  • 2021-07-07
  • 2021-11-02
  • 2021-11-14
猜你喜欢
  • 2022-12-23
  • 2021-08-19
  • 2022-12-23
  • 2021-12-27
  • 2021-06-13
  • 2021-06-16
相关资源
相似解决方案