Hayat Hasan
Hayat Hasan

Reputation: 229

Open Outlook successfully before add-in executes

I built a VSTO Outlook Addin (using Visual Studio) to copy emails from one folder to another followed by matching a few conditions.

I put the code under Sub ThisAddIn_Startup() which starts running at the beginning of the Outlook startup. This creates a delay of fully opening the Outlook application before executing this add-in functions. It takes a much longer time in processing the splash screen to open the main Outlook windows.

Is there any way that I can delay the execution of the add-in functions so that first - outlook will open successfully and emails will start to sync and then after certain time (say 5 minutes) the add-in will execute

I tried "Threading.Thread.Sleep()" but it freezes the whole process and adds extra delay time to open the Outlook application

Public Class ThisAddIn
   'Threading.Thread.Sleep(60000)  

   Public Sub ThisAddIn_Startup() Handles Me.Startup        
      Call CopyMails()
   End Sub

   Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
   End Sub

   Public Sub CopyMails()
      'Some codes here
   End Sub

End Sub

Upvotes: 1

Views: 170

Answers (1)

Jan Muncinsky
Jan Muncinsky

Reputation: 4408

I'm not sure whether there is not any better way with Outlook API to achieve your goal, but 5 minute delay can be achieved by:

Public Async Sub ThisAddIn_Startup() Handles Me.Startup
    Await Task.Delay(300000)
    CopyMails()
End Sub

Upvotes: 1

Related Questions