0

I did not work with Queue collection yet. But based on information I was able to gather it seems like this is a right approach to my problem.

I have console app that scan folder for new files of certain type. Based on specific criteria. Only new items are added to queue.xml file. This is done at some time interval (every 1 hour).

Another console app is triggered at different time point (every 4 hours). It reads queue.xml file and passes each item for processing. It seems that the best way is to parse xml file and create Queue collection. This way each item will be processed in order.

Here is problem. Processing file can take couple hours, and during that time queue.xml may have some new items, therefore Queue Collection will not reflect this changes.

Is it possible to parse xml file again and add new items to Queue that is currently in progress?

Changing size of the Collection during runtime will cause problems. Is it Queue different in that way?

tipitoe
  • 11
  • 2
  • 8
  • 2
    What's the schema of your XML file? Is it just filenames? Why is it an XML file? – itsme86 Aug 22 '16 at 20:31
  • XML contains filename, show name, episode title, encoding profile name, status. Some of this information needs to be passed to ffmpeg and handbrake for processing (filename) and the rest for post-processing. Since it is only couple items at given point of time and that they will be removed after they are completed I did not want to use database. Second, process of gathering items for later processing should be separate from actual encoding. From my experience that approach seems to be better. Sometimes you may encounter errors during encoding process. – tipitoe Aug 22 '16 at 20:58

1 Answers1

1

Is it possible to parse xml file again and add new items to Queue that is currently in progress?

Of course, you just have to define the rules by which it is safe for this to happen.

Use a mutex in both applications to lock the file during read/write, and in your processing application subscribe to a FileSystemWatcher event to detect when the file has changed.

Changing size of the Collection during runtime will cause problems. Is it Queue different in that way?

It can be safe to change the size of any collection at run time, that's usually why you use a collection (e.g. they have an Add() method for a reason)... you just have to do it safely, in the context of your solution.

If there is multi-thread access to the queue, lock it.

If there is a chance that the queue size can change during iteration, iterate over a copy of the queue.

If there is a chance that a process can change a file required by both applications, mutex it to control access.

Community
  • 1
  • 1
khargoosh
  • 1,450
  • 15
  • 40