mirror of
https://github.com/farcasclaudiu/SmartThreadPool.git
synced 2026-06-22 11:01:28 +03:00
v2.0
SmartThreadPool v2.0
This commit is contained in:
@@ -1,35 +1,34 @@
|
||||
using System;
|
||||
using Amib.Threading;
|
||||
|
||||
namespace Examples
|
||||
{
|
||||
public class SimpleExample
|
||||
{
|
||||
public void DoWork(object state)
|
||||
{
|
||||
SmartThreadPool smartThreadPool = new SmartThreadPool();
|
||||
public void DoWork(int[] numbers)
|
||||
{
|
||||
SmartThreadPool smartThreadPool = new SmartThreadPool();
|
||||
|
||||
// Queue the work item
|
||||
IWorkItemResult wir =
|
||||
smartThreadPool.QueueWorkItem(
|
||||
new WorkItemCallback(this.DoRealWork),
|
||||
state);
|
||||
// Queue the work item
|
||||
IWorkItemResult<double> wir = smartThreadPool.QueueWorkItem(new Func<int[], double>(CalcAverage), numbers);
|
||||
|
||||
// Do some other work here
|
||||
// Do some other work here
|
||||
|
||||
// Get the result of the operation
|
||||
object result = wir.Result;
|
||||
// Get the result of the operation
|
||||
double average = wir.Result;
|
||||
|
||||
smartThreadPool.Shutdown();
|
||||
}
|
||||
smartThreadPool.Shutdown();
|
||||
}
|
||||
|
||||
// Do the real work
|
||||
private object DoRealWork(object state)
|
||||
{
|
||||
object result = null;
|
||||
// Do the real work
|
||||
private double CalcAverage(int[] numbers)
|
||||
{
|
||||
double average = 0.0;
|
||||
|
||||
// Do the real work here and put the result in 'result'
|
||||
// Do the real work here and put
|
||||
// the result in 'result'
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return average;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user