Task and STA / MTA Threading Model

  • Thread starter Thread starter ChristianHavelDE
  • Start date Start date
C

ChristianHavelDE

Guest
Hi,

in our Outlook integration (Managed COM AddIn C#) we are using Tasks to execute some work in the background.

Well, on machines from one of our customers we receive the following exception, when one of our Dialogs is opened in Outlook.

Beim aufrufenden Thread muss es sich um einen STA-Thread handeln, da dies für viele Komponenten der Benutzeroberfläche erforderlich ist. (my translation: The calling Thread must be a STA-Thread, because this is required for some UI components)
bei System.Windows.Input.InputManager..ctor()
bei System.Windows.Input.InputManager.GetCurrentInputManagerImpl()
bei PresenceProfiles.<OnIsVisibleChanged>d__1.MoveNext()
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_1(Object state)
bei System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
bei System.Threading.ThreadPoolWorkQueue.Dispatch()
bei System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()


I think, that the problem is, that after a Task is finished, the following instructions are not executed in Outlooks main thread context. How do I force, that the instructions, that are executed after a task is finished are executed in the main thread context.

Best regards
Christian

Continue reading...
 
Back
Top