我有一个演员,有一个自定义计时器,以非实时间隔触发事件。 (这就是为什么我不能使用调度器) 在事件处理程序中,我想向自己或其他演员发送消息。我收到一个NotSupportedException。如何在akka.net的事件处理程序中发送消息?
我有一个自定义时间源similliar到NodaTime FakeClock类。
public class NodaTimeControllableClock
{
public void AddInterval(Duration interval);
public Instant Now { get; protected set; }
public event EventHandler<TimeChangedEventArgs<Duration>> TimeChanged;
}
它是在计时器类用于触发的时间每隔指定量的事件。
public class NodaTimer
{
Duration Interval { get; set; }
void Start();
void Stop();
bool IsRunning { get; private set; }
event EventHandler<TimerTickedEventArgs> TimerTicked;
}
现在,我为我的一些演员创建一个计时器实例并将其存储在它们中。
protected override void PreStart()
{
base.PreStart();
timer.Interval = Duration.FromSeconds(1);
timer.TimerTicked += Timer_TimerTicked;
timer.Start();
}
private void Timer_TimerTicked(object sender, TimerTickedEventArgs e)
{
Self.Tell(new SomeMessage());
//Here I want to send the message to the parent or
//if it's impossible to do so I could queue some message
//to the Self messagebox.
}
在事件上发送消息的模式是什么?有没有?
你能否提供一些简单的片断? – Horusiath
完成。这是否提供了足够的细节? –