STA mode Error

  • Thread starter Thread starter TWF0dA
  • Start date Start date
Status
Not open for further replies.
T

TWF0dA

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
 
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.

"Matt" <Matt> wrote in message

news:8C7BC51D-35DE-4A97-82C8-1D99066887B3@microsoft.com...
> 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
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
U Trouble with Cached Exchange Mode not fully implementing Using Outlook 3
J Outlook, Word, Access crash unless run in Admin mode - time dependent it seems Using Outlook 12
A Online Mode to Cached Exchange Mode problem Using Outlook 2
A Outlook 2016 in Cached Mode Using Outlook 1
N Shared mailbox in cached mode Using Outlook 0
W Receiving messages in offline mode Outlook VBA and Custom Forms 1
F "This action is not available in the current mode" Using Outlook 0
L Outlook Office 365 cached mode crashing Using Outlook 0
J Cached mode no longer works with NTLM authentication Exchange Server Administration 0
C Outlook 2016 Username Not Working in Scheduling Assistant (Cache Mode) Using Outlook 0
P Categorise emails on sending - macro not working in Preview mode Using Outlook 1
Diane Poremsky Say No! to Compatibility Mode Using Outlook 0
oliv- "Online mode with Exchange server" vs "online" Exchange Server Administration 2
Diane Poremsky Outlook Only Starts in Safe Mode? Using Outlook 0
R Microsoft Outlook 2010 - Non Cached Mode Using Outlook 0
R Outlook won't run except in Safe mode problem Using Outlook 5
P Outlook in safe mode Using Outlook 2
B Configure Outlook so Exchange uses cached mode but new items are by default saved to Outlook.com Using Outlook 1
TMok Outlook 2010 nop responds after I resumed the Wins8 from sleep mode Using Outlook 0
J BCM Crashing with Add-in Enabled in User Mode BCM (Business Contact Manager) 2
R Outlook Cache Mode Terminalserver disable through Registry Using Outlook 1
G Why won't VBA see a copied calendar in cache mode anymore? Outlook VBA and Custom Forms 20
2 How to use outlook 2003 calendar in always offline mode Using Outlook 0
Jennifer Murphy Sync RSS feed message after Safe Mode Using Outlook 3
K Following Several Power Cuts Can Only work in Safe Mode Using Outlook 0
P Reply All does not work in Outlook 2010 Cached mode Using Outlook 4
M Outlook 2010 stuck in Work Offline mode; trouble sending email Using Outlook 1
M Outlook 2010 slowness in cache mode Using Outlook 3
N Email Stuck in Outbox - Cached Mode - Roaming Profile Using Outlook 2
U Cached mode additional mailboxes Using Outlook 2
L Macro mode Using Outlook 2
K Outlook Cached Mode - can't create rules to move email to another mailbox Using Outlook 2
R "business contact manager logon failure server is in single user mode" - HELP! BCM (Business Contact Manager) 4
T passwords in outlook 2000(in XP Virtual PC mode) under Windows 7 Professional Using Outlook 6
W disabled cached mode, but Outlook still using OST Using Outlook 2
M Outlook only starts in safe mode Using Outlook 4
S Cached Exchange Mode and roaming users Using Outlook 5
P Outlook 2010 search of PST files doesn't work unless in cached mode Using Outlook 3
R Share ost between connector and exchange cache mode = "everything everywhere" Using Outlook 3
S Outlook 2010 Terminalserver Cache Mode Instant Search Using Outlook 4
P Migrate profile - cached mode setting Using Outlook 2
D Event on connection mode change? Outlook VBA and Custom Forms 2
P How to know Outlook is being started in Offline mode? Outlook VBA and Custom Forms 2
S Unable to enumerate Mailboxes in NON Cached Mode (if more than 2) Outlook VBA and Custom Forms 8
E BCM instalation in terminal services mode BCM (Business Contact Manager) 1
Q Otlk 2007 does not block when in "always prompt for..." mode Outlook VBA and Custom Forms 2
T Code to import address book in automatic mode Outlook VBA and Custom Forms 1
S Correct way to Identify is Mail is opened in Edit Mode Outlook VBA and Custom Forms 1
A outlook cache mode Outlook VBA and Custom Forms 1
Sandgroper48 Automation Error Outlook VBA and Custom Forms 12

Similar threads

Back
Top