I need to convert thousands of ms office documents in different formats into one common format. To get things faster i would parallelize it using akka.net for. The WordSaveAsActor should:
- run in Single-Threaded Appartment
- hold the Word Application instance
- make COM calls on this instance, like SaveAs(..) with paths from received messages from multiple parallel threads
- restart itself by any crash
Is it even possible to run akka.net actor in STA? Is there any concerns if I use the akka.net this way?
The short answer is "yes, you can do this with Akka.NET"
As Hans points out in his comment:
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.
In your case, here's what I'd recommend you do:
WordSaveAsActor
on the STA thread and configure it to use theCurrentSynchronizationContextDispatcher
in Akka.NET, which you can do via configuration: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. We use this technique in other STA environments, such as Windows Forms UI, and it greatly simplifies everything.
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. 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.