The behaviours is really strange, it looks like a massive bug in the framework itself,
I have a FileSystemWatcher to detect new files in a folder, and everytime a new file is detected, that file is parsed and deleted before an Rx .OnNext notification is sent:
private Subject<MyObject> objectNotification = new Subject<MyObject>();
private FileSystemWatcher watcher;
private void MyClassConstructor(string pathToWatch)
{
watcher= new FileSystemWatcher();
watcher.Filter = scraper.Ext;
watcher.Created += new FileSystemEventHandler(parseMethod);
watcher.Path = pathToWatch;
watcher.EnableRaisingEvents = true;
}
private void parseMethod(object sender, FileSystemEventArgs e)
{
MyObject parsedFile = new MyObject(e.FullPath);
File.Delete(e.FullPath);
var syncedSubject = Subject.Synchronize(objectNotification);
syncedSubject.OnNext(parsedFile);
}
On the other side, somewhere in the GUI code of the main application there's a receiving code:
private IDisposable myObjectSubscription;
.
.
.
private void initSubscription()
{
this.myObjectSubscription = sendingClass.Subscribe(parsedObject =>
{
this.AddObject(parsedObject);
});
}
private void addObject(MyObject parsedObject)
{
//Sometimes the same object is being received many times, but has been sent only once!
//BUG!
}
ideally I should receive a notification within the observer for each value sent by the sender class, unfortunately I get more, a lot more!