A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

STA mode Error



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 14th 09, 03:44 PM posted to microsoft.public.outlook.program_addins
Matt
external usenet poster
 
Posts: 119
Default STA mode Error

Hello,

I wasn't getting this error until I threw my code, which initiated/called my
Form to load, into a try/catch statement.

"Current thread must be set to single thread apartment (STA) mode before OLE
calls can be made. Ensure that your Main function has STAThreadAttribute
marked on it."

I don't have a Main function in my code for my COM add-in for Outlook, so
how would I go about fixing this error so that I can load my Form.

Thanks
  #2  
Old May 14th 09, 07:47 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default STA mode Error

That error usually occurs in relation to WordMail objects in Outlook 2003 or
earlier. In that case WordMail is not running in the same process space as
Outlook is and the threading is different. It also can happen from
background threads (which never, ever should be used to access the Outlook
object model).

Your Connect class is running in process with Outlook and in the same
thread. You would need to set up a callback into the main thread. I usually
get the current thread context in Connect, at NewInspector() and
NewExplorer(). Often to prime the message pump I call
System.Windows.Forms.Application.DoEvents() before I get the context so it
isn't null.

I then store that context and put any thread sensitive code in Connect so it
runs in the main thread. When I need to synch to that thread I use a
System.Threading.SendOrPostCallback utilizing the persisted main thread
context.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Matt" wrote in message
...
Hello,

I wasn't getting this error until I threw my code, which initiated/called
my
Form to load, into a try/catch statement.

"Current thread must be set to single thread apartment (STA) mode before
OLE
calls can be made. Ensure that your Main function has STAThreadAttribute
marked on it."

I don't have a Main function in my code for my COM add-in for Outlook, so
how would I go about fixing this error so that I can load my Form.

Thanks


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook SP2 Cached mode.Opening shared calendar-Permission error Didier Outlook - Calandaring 0 June 7th 07 09:20 PM
Error: Rejected Safe Mode action : Microsoft Office Outlook. Ryan Close Outlook - Installation 0 December 13th 06 02:19 PM
what does error code office in off line mode mean{Outlook} dapperz Outlook - Installation 1 November 8th 06 04:17 PM
how do i change outlook 2003 back to regular mode from "safe mode CCSMUDGE Outlook - Installation 0 July 5th 06 01:26 AM
Cached Exchange Mode Terminal Services Error Dennis Procopio Outlook - Installation 7 June 14th 06 04:27 PM


All times are GMT +1. The time now is 10:39 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.