public async Task Test(bool TaskPool) { IActorFactory fact = new ActorFactory(t => t.Priority = _Priority); var One = new PingPonger("Bjorg"); IPingPonger Actor1 = fact.Build <IPingPonger>(One); var Two = new PingPonger("Lendl"); var fact2 = TaskPool ? new TaskPoolActorFactory() : fact; IPingPonger Actor2 = fact2.Build <IPingPonger>(Two); One.Ponger = Actor2; Two.Ponger = Actor1; var watch = new Stopwatch(); watch.Start(); await Actor1.Ping(); Thread.Sleep(10000); var lifeCyle = Actor2 as IActorCompleteLifeCycle; Task Task2 = (lifeCyle == null) ? TaskBuilder.Completed : lifeCyle.Abort(); await Task.WhenAll(((IActorCompleteLifeCycle)(Actor1)).Abort(), Task2); watch.Stop(); Console.WriteLine("Total Ping:{0} Total Time: {1}", One.Count, watch.Elapsed); Console.WriteLine(One.Count); Console.WriteLine(Two.Count); }
public async Task PingPong(IPingPonger other, int further) { int c = Interlocked.Increment(ref _currReqCount); _qReqCounts.Enqueue(c); await Task.Delay(10); if (further > 0) { await other.PingPong(this, further - 1); } Interlocked.Decrement(ref _currReqCount); }