SmartThreadPool v2.0
This commit is contained in:
Ami Bar
2009-12-19 16:32:41 +02:00
parent b30b4abdda
commit 4d6ffb5851
89 changed files with 13714 additions and 2639 deletions
+20 -21
View File
@@ -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;
}
}
}