Exemplo n.º 1
0
 private Task IncreaseCounter(IncreaseCount data)
 {
     // Interlocked.Add(ref Counter.Count, data.Amount);
     Counter.Count += data.Amount;
     Task.Run(async() => await CheckMailBox());
     return(Task.CompletedTask);
 }
Exemplo n.º 2
0
        public void Run()
        {
            var actorFactory = new ActorFactory();
            var m            = actorFactory.GetActor <Manager>(new Guid());
            var w1           = actorFactory.GetActor <Worker>(new Guid()) as Worker;
            var w2           = actorFactory.GetActor <Worker>(new Guid()) as Worker;

            var msg = new IncreaseCount(2);

            Task.Run(async() =>
            {
                for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < 10000; j++)
                    {
                        await m.SendMessage(w1, msg);
                        await m.SendMessage(w2, msg);
                        await m.SendMessage(w1, msg);
                        await m.SendMessage(w2, msg);
                    }
                }
            });

            while (true)
            {
                Console.ReadLine();
                System.Console.WriteLine($"w1 Counter : {w1.Counter.Count}");
                System.Console.WriteLine($"w2 Counter : {w2.Counter.Count}");
                System.Console.WriteLine($"w1 MailBox : {w1.MailBox.Count}");
                System.Console.WriteLine($"w2 MailBox : {w2.MailBox.Count}");
            }
        }