473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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");
}

}
}
Nov 17 '05 #1
2 5212

"Julien @ BE" <ba*****@hotmail.com> wrote in message
news:c1**************************@posting.google.c om...
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 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.
Nov 17 '05 #2
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.

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Jorge Godoy | last post by:
Hi! I must have been searching in the wrong places or with the wrong keywords but I couldn't find out how to implement something such as what is done by the threading module on Windows (95, 98...
3
by: Jason | last post by:
Hi, I've been having trouble understanding the difference between global namespace within and between modules. For example, I can program a subthread to see a global name (a threaded event to...
2
by: c duden | last post by:
I am able to add an exisiting office addin project to a blank solution in VS.NET 2003. When I attempt to add it's setup project I get the following error in VS.NET "Cannot change threading mode...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
8
by: Z D | last post by:
Hello, I'm having a strange problem that is probably due to my lack of understanding of how threading & COM Interop works in a WinForms.NET application. Here's the situation: I have a 3rd...
13
by: John | last post by:
I've got some reasonably complex business logic in my C# code, in a class called by a ASP.NET page. This takes around 3-4 seconds to execute. It's not dependent on SQL calls or anything like that....
0
by: Pawan Narula via DotNetMonster.com | last post by:
hi all, i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode...
5
by: Miro | last post by:
I will try my best to ask this question correctly. I think in the end the code will make more sence of what I am trying to accomplish. I am just not sure of what to search for on the net. I...
3
by: Donald A. Fisher | last post by:
Hello. I've been working a vb project and have a form with a button on it that performs some actions after disabling the button when clicked: Code disabling button and starting actions: Private...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.