public static void TestInvoker()
{
var range = Arrays.Range(0, 1, 100);
var list = new List<int>();
IAsyncResult result = null;
using (var sti = new SingleThreadedInvoker())
{
foreach (int i in range)
{
int j = i;
if (j % 2 == 0)
result = sti.BeginInvoke(new Action(() =>
{
list.Add(j);
}), new object[0]);
else
sti.Invoke(new Action(() =>
{
list.Add(j);
}), new object[0]);
}
// wait for all to finish
sti.EndInvoke(result);
}
if (!list.SequenceEqual(range))
throw new Exception("SingleThreadedInvoker failed!");
}