private void DeQueue() { while (!stopFlag) { workUnit item = workUnits.Take(); item.SetState("Processing Started"); try { DoLongRunningDBStuff(workUnit); item.SetState("Processing Successful"); } catch { item.SetState("Processing Failed"); } } }
double measureWorkUnitsPerSecond(int noThreads, int testDurationMs, workUnit work, string caption) { int completedThreads = 0; object l = new object(); int units = 0; StopWatch sw = new StopWatch(); var go = new ThreadStart( delegate() { int u = 0; try { while (sw.ElapsedMS < testDurationMs && !_break) { work(); units++; } } catch { } lock (l) { completedThreads++; units += u; } } ); List<Thread> threads = new List<Thread>(); for (int t = 0; t < noThreads; t++) threads.Add(new Thread(go)); sw.Start(); foreach (var t in threads) t.Start(); while (completedThreads < noThreads) { _break = Info.BreakExecution; Thread.Sleep(50); } sw.Stop(); return units / (sw.ElapsedMS / 1000); }
public void EnQueue(workUnit item) { workUnits.Add(item); }
public Task EnQueue(workUnit item) { // Schedule the work on the thread pool. // If you need limited concurrency here, there are schedulers to enable this. return(Task.Run(() => DoLongRunningDBStuff(item))); }