I start a Task from the main (GUI) thread, and await
for it.
It runs long time, but does not block the GUI. Nice.
However, if I call a COM function in it, it blocks the main thread.
Code:
class TaskCreater
{
internal System.Threading.Tasks.Task Run()
{
return System.Threading.Tasks.Task.Run(() =>
{
System.Threading.Thread.Sleep(10000); // --> nice, no blocking GUI for 10 sec
COMClass.LongFunction(); // -> not nice, blocks to GUI
});
}
}
Caller GUI thread:
await _taskCreator.Run();
MSDN: Task.Run Method: Queues the specified work to run on the ThreadPool and returns a task or Task handle for that work.
So why is then that COM call blocks the caller thread?
And why Sleep() does not then?
I expect both to run in a background thread.