文件监控系统响应式编程 [英] File Monitoring System Reactive Programming
问题描述
我正在使用 C#.我是响应式编程的新手.使用反应式编程,我想创建一个文件夹监控系统,如果文件夹 A 包含任何文件,如果是,它将调用该文件 &处理它并将其移动到文件夹 B 中.假设文件夹 A 首先是空的.用户实时将一些文件添加到文件夹 A 中.系统检测到新文件已添加 &它会一一或同时处理.我无法理解我应该使用 Create 或 Interval ,之后我的处理代码将在哪里编写请帮帮我
I am using C#.I am new to reactive programming. Using reactive programming, I want to create a folder monitoring system which will invoke if folder A contains any file if yes then it will grab that file & process it and move it in Folder B. Let say, Folder A is empty first.User adds some files into folder A realtime. System detects that new files has been added & it will process it one by one or simultaneously. I am not able to understand what should I use Create or Interval and after that where will be my processing code be written Please help me
推荐答案
这应该相当接近:
var query =
Observable
.Using(
() =>
{
var fsw = new FileSystemWatcher(@"C:\A");
fsw.EnableRaisingEvents = true;
return fsw;
},
fsw => Observable.FromEventPattern<FileSystemEventHandler, FileSystemEventArgs>(
h => fsw.Created += h,
h => fsw.Created -= h))
.Delay(TimeSpan.FromSeconds(0.1));
query
.Subscribe(x => File.Move(x.EventArgs.FullPath, Path.Combine(@"C:\B", x.EventArgs.Name)));
这篇关于文件监控系统响应式编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!