I have a console application which uses an external library. The library insists on always being called from the same thread; it locks up otherwise. (I did try runn
Since ExecuteInWorkerThread
runs all actions on one thread, it will block if called recursively. So I suspect your hang maybe because you have an action calling the library, which then calls the library again via ExecuteInWorkerThread
before completing.
I've not tested your ThreadManager class; my gut says it looks too complicated though, so as an aside, if you don't mind including Reactive Extensions (nuget package rx-main), then you can refactor your ThreadManager class like this:
public class ThreadManager
{
EventLoopScheduler _scheduler = new EventLoopScheduler();
public T ExecuteInWorkerThread(Func action)
{
return Observable.Start(action, _scheduler).Wait();
}
}
And you can add this method to it if you need an async call too:
public Task ExecuteInWorkerThreadAsync(Func action)
{
return Observable.Start(action, _scheduler).ToTask();
}