Akka.Net 中的 ContinueWith 异常不会重新启动
Exception in ContinueWith in Akka.Net does not restart
我在 AKKA.NET actor
中有以下代码
Receive<UploadFileFromDropboxMessage>(msg =>
{
var sender = Sender;
var self = Self;
UploadFromDropboxToBlobStorageAsync(msg.Path, msg.RelativeSourceRootDirectory).ContinueWith(o =>
{
if (o.Exception is null)
{
sender.Tell(new UploadFileFromDropboxSuccessMessage(msg.Path), self);
sender.Tell(new ReadyForWorkMessage(), self);
}
else
{
throw o.Exception;
}
}, TaskContinuationOptions.ExecuteSynchronously).PipeTo(Self);
});
当在 ContinueWith 中重新抛出异常时,actor 不会重新启动。为什么不?
ContinueWith
作为 actor 外部的延续 Task
执行。将在执行该延续的任何线程上抛出异常,而不是在 actor 的范围内。
await
如果您想在 actor 内部处理该异常,则使用 ReceiveAsync<T>
处理程序在 actor 内部 UploadFromDropboxToBlobStorageAsync
。
我在 AKKA.NET actor
中有以下代码 Receive<UploadFileFromDropboxMessage>(msg =>
{
var sender = Sender;
var self = Self;
UploadFromDropboxToBlobStorageAsync(msg.Path, msg.RelativeSourceRootDirectory).ContinueWith(o =>
{
if (o.Exception is null)
{
sender.Tell(new UploadFileFromDropboxSuccessMessage(msg.Path), self);
sender.Tell(new ReadyForWorkMessage(), self);
}
else
{
throw o.Exception;
}
}, TaskContinuationOptions.ExecuteSynchronously).PipeTo(Self);
});
当在 ContinueWith 中重新抛出异常时,actor 不会重新启动。为什么不?
ContinueWith
作为 actor 外部的延续 Task
执行。将在执行该延续的任何线程上抛出异常,而不是在 actor 的范围内。
await
如果您想在 actor 内部处理该异常,则使用 ReceiveAsync<T>
处理程序在 actor 内部 UploadFromDropboxToBlobStorageAsync
。