I have this Class:
public class PCQueue : IDisposable
{
public delegate void OnFileAddDelegate(string file);
public event OnFileAddDelegate OnFileAddEventHandler;
BlockingCollection<Action> _taskQ = new BlockingCollection<Action>();
public PCQueue (int workerCount)
{
// Create and start a separate Task for each consumer:
for (int i = 0; i < workerCount; i++)
Task.Factory.StartNew (Consume);
}
public void Dispose() { _taskQ.CompleteAdding(); }
public void EnqueueTask (Action action) { _taskQ.Add (action); }
void Consume()
{
// This sequence that we’re enumerating will block when no elements
// are available and will end when CompleteAdding is called.
foreach (Action action in _taskQ.GetConsumingEnumerable())
action(); // Perform task.
}
}
And i have string[]
that i want to add into my Queue
and after that i want my Consume()
get this files in order to processing.
string[] files;
PCQueue pq = new PCQueue(1);
foreach (string item in files)
pq.EnqueueTask(item);
i have this error: cannot convert from 'string' to 'System.Action'
After i put file from my Queue
i am check this file:
Checker checker = new Checker ();
string result = Checker.Check(my file from the Queue);
if (result != null && OnFileAddEventHandler != null)
OnFileAddEventHandler(result);
And if this file is OK i fired up event to my form