CDO & threading : Cannot change thread mode after it is set.

CDO & threading : Cannot change thread mode after it is set.

Post by barbez » Thu, 14 Apr 2005 17:55:41


When trying to run this code, I get the following error message :
Unhandled Exception: System.Runtime.InteropServices.COMException
(0x80010106): Cannot change thread mode after it is set.

1. Anyone an idea why ?
2.Does anyone knows a better way than CDO to connect a mailbox on a
Exchange 5.5 server ?


Thanks


using System;
using System.Threading;

namespace MailConnections
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{


/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{


Class1 c1 = new Class1();
Thread t1 = new Thread(new ThreadStart(c1.connect));

//c1.connect(); //works perfect
t1.Start();

Console.ReadLine();
}

public void connect()
{
MAPI.Session session = new MAPI.Session();
Console.WriteLine("Session created");
}

}
}
 
 
 

CDO & threading : Cannot change thread mode after it is set.

Post by Willy Deno » Thu, 14 Apr 2005 18:44:44


CDO is STA only. Initialize you thread as STA before starting and your
problem will be gone.
Not sure why you need to run this on a separate thread though, seems like
everyone needs multiple threads these day's.

Willy.

 
 
 

CDO & threading : Cannot change thread mode after it is set.

Post by Julien » Thu, 14 Apr 2005 19:34:01

Thanks Willy, it works now perfect...

I'm developping an application that needs to make several logons on an
exchange server and do several operations simultaneously... that's why
multiple threads.