本文整理匯總了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);
}
}
}