At present my program is able to process an image that has just been created, with the use of an event raised by FileSystemWatcher. But the algorithm haltedin the case of more than one raised event due to a 'Object is used elsewhere' error, caused by the Bitmap being accessed by multiple threads. This is why I would like to rewrite te pipeline.
What is a good way to queue the events, and only process them when the previous image is done processing? I currently can only come up with intuitively problematic constructions like 'while(!currentlyBusy)' at the top of the event handler. This potentially results in the while loop being true for multiple threads, in case of 2+ raised events at the moment an image is processed, which can violate chronology.
My code has this gist:
public Pipeline() { InitializeComponent();
var fileSystemWatcher = new FileSystemWatcher(@"inputImagesPath") { // options }; fileSystemWatcher.Created += OnFileCreated;
---> now put the subscriber OR imagepath OR any usefull specifics in a queue from which only the first element will be processed when there is only the main thread running. }