Access to Outlook object in other thread

Add-in Express™ Support Service
That's what is more important than anything else

Access to Outlook object in other thread
 
Evgeny Tatarincev




Posts: 1
Joined: 2009-04-09

 public class AddinModule : AddinExpress.MSO.ADXAddinModule
{
  private static Outlook.MAPIFolder _oFolder;
  ...
  private void AddinModule_AddinInitialize(object sender, EventArgs e)
  {
	Outlook._NameSpace ns = OutlookApp.GetNamespace("MAPI");
	_oFolder =
           ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

       //acess to _oFolder in module thread
       bool bTest = _oFolder.Items.Count > 1;
       Thread  myThread = new Thread(new ThreadStart(ThreadProc));
        myThread.Start();      
  }

  private void ThreadProc()
  { 
    //acess to _oFolder in other thread
    bool bTest = _oFolder.Items.Count > 1 //Function evaluation disabled 
                                          //because a previous function 
                                          //evaluation timed out. 
                                          //You must continue execution 
                                          //to reenable function valuation.
  }
  ...

}


I'm see all post in this forums. And do not find resolution this problem.
All threading examples in forum posts using static outlook variables correctly. Sorry for my english.
Posted 09 Apr, 2009 10:37:24 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Evgeny,

The Excel Object Model isn't thread safe. You need to use it in the main thread only.


Andrei Smolin
Add-in Express Team Leader
Posted 09 Apr, 2009 10:46:54 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Sorry for the misprint. I mean the Outlook object model, of course.


Andrei Smolin
Add-in Express Team Leader
Posted 09 Apr, 2009 10:53:42 Top