Hey Guys I am a newbie in office addin programming and now I am working on creating an addin for outlook. The purpose of this outlook addin is to fetch all incoming mails in each account's inbox and send them to my server. I've successfully done it with Microsoft.Office.Interop.Outlook, though I have some problems with it. Here is my code http://pastebin.com/TwnmrYeY and below are the problems
- As far as I know the work can't be done in the main UI thread so I create another thread that runs seperately from the main thread. I loop the AccessEmails function to get new incoming mails, since ItemsEvents_ItemAddEventHandler can't handle it if there are a bunch of incoming mails. The problem is the background thread sometimes won't stop when the outlook is already closed.
- I want to wait for the synchronization send/receive to finish before fetch all the emails, I've tried to use Application.Session.SyncObjects and add event handler for SyncStart,SyncEnd, and OnError but still it is often crashed. The crash happen when the synchronization is ongoing but I close the outlook application.
- How to reduce memory consumption while iterating through all emails in an inbox, I use Outlook.Items to iterate all the emails and it consumes a pretty large memories?
I hope you guys can help me since I've been stuck pretty long in these stuffs.