[英]Akka.net actors in STA
I need to convert thousands of ms office documents in different formats into one common format. 我需要将成千上万种不同格式的Office文档转换为一种通用格式。 To get things faster i would parallelize it using akka.net for.
为了使事情更快,我将使用akka.net对其进行并行化。 The WordSaveAsActor should:
WordSaveAsActor应该:
Is it even possible to run akka.net actor in STA? 甚至可以在STA中运行akka.net actor吗? Is there any concerns if I use the akka.net this way?
如果我以这种方式使用akka.net,是否有任何担忧?
The short answer is "yes, you can do this with Akka.NET" 简短的答案是“是的,您可以使用Akka.NET做到这一点”
As Hans points out in his comment: 正如汉斯在评论中指出的那样:
Word doesn't care much about your library.
Word不太在乎您的图书馆。 Its interop interface is single-threaded, any call you make from a worker thread is automatically marshaled to the thread that owns the Application object.
它的互操作接口是单线程的,您从工作线程进行的任何调用都会自动编组到拥有Application对象的线程中。
You can use the dispatchers in Akka.NET to exercise some control over your actors' concurrency needs - you can read about different types of Akka.NET dispatchers and how they work in our Akka.NET Bootcamp Lesson 2.1 . 您可以使用Akka.NET中的调度程序对参与者的并发需求进行一些控制-您可以在Akka.NET Bootcamp课程2.1中了解不同类型的Akka.NET调度程序以及它们的工作方式 。
In your case, here's what I'd recommend you do: 对于您而言,这是我建议您执行的操作:
WordSaveAsActor
on the STA thread and configure it to use the CurrentSynchronizationContextDispatcher
in Akka.NET, which you can do via configuration: WordSaveAsActor
并将其配置为使用Akka.NET中的CurrentSynchronizationContextDispatcher
,可以通过配置来完成: var wordActor = MyActorSystem.ActorOf(Props.Create(() => new WordSaveAsActor(...)).WithDispatcher("akka.actor.synchronized-dispatcher"))
All messages this actor processes will be done automatically on the STA thread. 这个参与者处理的所有消息将在STA线程上自动完成。 We use this technique in other STA environments, such as Windows Forms UI, and it greatly simplifies everything.
我们在其他STA环境(例如Windows Forms UI)中使用了此技术,它大大简化了一切。
WordSaveAsActor
. WordSaveAsActor
。 As Hans points out, unless you run multiple instances of Word in parallel you can't really do more than one operation at a time leveraging its COM API. 正如汉斯指出的那样,除非您并行运行Word的多个实例,否则利用它的COM API一次实际上不能做多个操作。 So in order to take advantage of Akka.NET's parallelism you'll need to find a way to use multiple actors to parallelize the parts of your operation that don't require Word.
因此,为了利用Akka.NET的并行性,您需要找到一种方法来使用多个参与者来并行化不需要Word的操作部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.