I am writing a service to read data values from simulator. When I try to debug my service I am receiving following exception: "ActiveX Control cannot be instantiated because the current thread is not in a single threaded apartment". Any help in this regard is very much appreciated.
Asked
Active
Viewed 151 times
0
-
You are most likely creating the ActiveX control on a background thread. For example, `Task.Run` will execute code on a background thread. – Martin Liversage Apr 07 '17 at 07:11
-
1The error message seems painfully clear. And there are lots of topics on Stack Overflow already discussing STA threads and how to make one. You didn't provide a good [mcve] that shows exactly how you got the error, but note that one possible fix is to apply [STAThread] to an entry point method (per marked duplicate). Other fixes are similar; they just involve using other techniques for setting the thread to be STA. – Peter Duniho Apr 07 '17 at 07:13
-
1@PeterDuniho - or the other fix - realising that the component was never intended to be used in the context of a service. – Damien_The_Unbeliever Apr 07 '17 at 07:16
-
I am invoking the dll file which inturn invokes the winform to se the COM components. – Sameer Betageri Apr 07 '17 at 07:24