내가이 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.
}
}
을 그리고 난 내가 내 Queue
에 추가 할 string[]
을 가지고 있고 그 후 내가 원하는 내 Consume()
처리하기 위해이 파일을 얻을.
string[] files;
PCQueue pq = new PCQueue(1);
foreach (string item in files)
pq.EnqueueTask(item);
이 오류가 있습니다
Checker checker = new Checker();
string result = Checker.Check(my file from the Queue);
if (result != null && OnFileAddEventHandler != null)
OnFileAddEventHandler(result);
그리고 만약 : 나는이 파일을 확인 오전 내 Queue
에서 파일을 넣어 한 후 'System.Action'에서 '문자열'
에서 변환 할 수 없습니다 이 파일은 괜찮습니다. 내 양식에 이벤트를 발생 시켰습니다.
확실히 대기열에 작업이 아닌 데이터가 있어야합니까? –
@MatthewWatson 아니, 전체 요점은 미리 정의 된 수의 작업자가있는 파일 컬렉션을 처리하는 것 같아서,'Action'처리가 큐에 저장되거나'Action's의 대기열 중 하나입니다. –
AndreySarafanov
@AndreySarafanov이 경우 작업 배열을 만들고 Parallel.Invoke()를 사용하여 작업을 시작하고 작업 항목에 BlockingCollection을 사용하면됩니다. –