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.
}
Aravind GovindarajPosted Oct 25, 2022, 2:48 PM
We have multiple approaches here, please find the same
1. once the file is consumed, please rename the file as something like filename.jpg.process. so your system will pick only the *.jpg file, which eventually omits the processing file. Make sure if there is any issue make the file name as the original status.
2. object lock mechanism. if the module is busy it will wait for completion.
3. Create a Temp folder, when you start processing the file, move one or more files into the temp folder, that's is the runtime folder where it will create the on-demand basis and delete once its job done.