本文整理汇总了C#中Actor.Start方法的典型用法代码示例。如果您正苦于以下问题:C# Actor.Start方法的具体用法?C# Actor.Start怎么用?C# Actor.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Actor
的用法示例。
在下文中一共展示了Actor.Start方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Spawn
public static ActorReference Spawn(this Silo silo, string processName, Action<object, Sender, Actor> action)
{
var task = Task.Run(() =>
{
var serializer = silo.MessageSerializerFactory.GetNewSerializer();
using (var actor = new Actor(silo.Context, serializer, processName, processName, action))
{
actor.Start();
}
});
return new ActorReference { ActorReferenceTask = task, Address = processName, ActorFactory = silo.ActorFactory, MessageSerializerFactory = silo.MessageSerializerFactory};
}
示例2: Start
public void Start()
{
Actor a = new Actor(() =>
{
var nums = Enumerable.Range(1, __count).ToList();
nums.ForEach(
n =>
{
System.Threading.Thread.Sleep(1000);
int recv = 0;
var sender = Actor.Self().receive<int>(ref recv, 0);
Console.WriteLine(string.Format("actor {0} received {1}", Actor.Self().Name, recv));
recv++;
Actor.Self().send<int>(sender, recv, 0);
});
}) { Name = "a" };
Actor b = new Actor(() =>
{
int recv = 0;
var nums = Enumerable.Range(1, __count).ToList();
nums.ForEach(n =>
{
Actor.Self().send<int>(a, recv, 0);
System.Threading.Thread.Sleep(1000);
var sender = Actor.Self().receive<int>(ref recv, 0);
Console.WriteLine(string.Format("actor {0} received {1}", Actor.Self().Name, recv));
recv++;
});
}) { Name = "b" };
a.Start();
b.Start();
}
示例3: CallKillMe
public void CallKillMe()
{
using (var context = NetMQContext.Create())
{
using (var exchange = new Exchange(context))
{
exchange.Start();
using (var customer = new Actor<Customer>(context, new BinarySerializer()))
{
Thread.Sleep(300);
Task.Run(() => customer.Start());
}
exchange.Stop(true);
}
}
}