Forking threads in VSTO outlook add-in
Forking threads in VSTO outlook add-in
I've a toolbar add-in that is intended to add selected mails to a very slow internal archive. At the moment I loop through each email one at a time, which is painfully slow.
Am I allowed to fork a thread for each upload from my add-in and then join when all done? or is that banned from within the Outlook sandbox?
1 Answer
1
Apologies for the lazy question, for anyone who finds it in the future, there's nothing that prevents you from creating threads in a VSTO application. The test sub(s) below can be used to confirm this:
Private Sub Button3_Click(sender As Object, e As RibbonControlEventArgs) Handles Button3.Click
Dim myData As String() = New String() "a", "b", "c"
Debug.WriteLine("Starting")
Using signalEv As CountdownEvent = New CountdownEvent(1)
For Each s As String In myData
signalEv.AddCount()
ThreadPool.QueueUserWorkItem(Sub(state)
Try
ProcessData(state)
Finally
signalEv.Signal()
End Try
End Sub,
s)
Next
signalEv.Signal()
signalEv.Wait()
End Using
Debug.WriteLine("all done")
End Sub
Private Sub ProcessData(s As String)
Debug.WriteLine(Thread.CurrentThread.ManagedThreadId.ToString & " data: " & s)
End Sub
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy