Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
date: Wed, 4 Jun 2008 16:02:37 +0100,    group: microsoft.public.platformsdk.mapi        back       


MAPI in mutithreading environments   
Hi,

I'm trying to use MAPI in a windows service but I've got the multithreading 
problem when trying to use the session on a separate thread(timer tick 
event). If I run everything on the main thread (STAThread) everything works 
great.

In the documentation it says that MAPIInitialize() should be called on each 
thread you intend to use mapi in. How can I do this from .NET? What is the 
coresponding method in .NET?

I get the errors when I try to create a session instance like:
objSession = new MAPI.Session()

This works in the main thread but if I do that again on any other thread it 
crashes. I tried to cache the session object in the main thread and reuse it 
everywhere but objSession.LogOff() get in an infinite loop internally.

Thanks,
Cosmin
date: Wed, 4 Jun 2008 16:02:37 +0100   author:   Cosmin Onea

Re: MAPI in mutithreading environments   
MAPI.Session will call MAPIInitialize internally.
What is the exact error that you get?
You do know that MS does not support CDO 1.21 from .Net, right?

-- 
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool
-
"Cosmin Onea"  wrote in message 
news:ec5FIRlxIHA.2208@TK2MSFTNGP04.phx.gbl...
> Hi,
>
> I'm trying to use MAPI in a windows service but I've got the 
> multithreading problem when trying to use the session on a separate 
> thread(timer tick event). If I run everything on the main thread 
> (STAThread) everything works great.
>
> In the documentation it says that MAPIInitialize() should be called on 
> each thread you intend to use mapi in. How can I do this from .NET? What 
> is the coresponding method in .NET?
>
> I get the errors when I try to create a session instance like:
> objSession = new MAPI.Session()
>
> This works in the main thread but if I do that again on any other thread 
> it crashes. I tried to cache the session object in the main thread and 
> reuse it everywhere but objSession.LogOff() get in an infinite loop 
> internally.
>
> Thanks,
> Cosmin
>
date: Wed, 4 Jun 2008 11:34:29 -0700   author:   Dmitry Streblechenko

Re: MAPI in mutithreading environments   
If I don't do session = new MAPI.Session() on the main thread I get this:
Retrieving the COM class factory for component with CLSID 
{3FA7DEB3-6438-101B-ACC1-00AA00423326} failed due to the following error: 
80010106.

If I get the session on the main thread I can't call LogOff on any other 
thread. Most probably because the main thread is waiting for a key(console 
application) to exit so the STA the session lives in can't pump messages.

No problems if I do everything on the main thread but that's not what I want 
because I have  other things to do and eventually the console application 
will become a windows service.

I read that they don't support 1.21 in .NET but in the same time I read a 
book that presents .net samples of mapi applications.

Cheers,
Cosmin

"Dmitry Streblechenko"  wrote in message 
news:eU$4gGnxIHA.548@TK2MSFTNGP06.phx.gbl...
> MAPI.Session will call MAPIInitialize internally.
> What is the exact error that you get?
> You do know that MS does not support CDO 1.21 from .Net, right?
>
> -- 
> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy  - Outlook, CDO
> and MAPI Developer Tool
> -
> "Cosmin Onea"  wrote in message 
> news:ec5FIRlxIHA.2208@TK2MSFTNGP04.phx.gbl...
>> Hi,
>>
>> I'm trying to use MAPI in a windows service but I've got the 
>> multithreading problem when trying to use the session on a separate 
>> thread(timer tick event). If I run everything on the main thread 
>> (STAThread) everything works great.
>>
>> In the documentation it says that MAPIInitialize() should be called on 
>> each thread you intend to use mapi in. How can I do this from .NET? What 
>> is the coresponding method in .NET?
>>
>> I get the errors when I try to create a session instance like:
>> objSession = new MAPI.Session()
>>
>> This works in the main thread but if I do that again on any other thread 
>> it crashes. I tried to cache the session object in the main thread and 
>> reuse it everywhere but objSession.LogOff() get in an infinite loop 
>> internally.
>>
>> Thanks,
>> Cosmin
>>
>
>
date: Thu, 5 Jun 2008 09:03:51 +0100   author:   Cosmin Onea

Re: MAPI in mutithreading environments   
The error is RPC_E_CHANGED_MODE.
You can create a session on the main thread, log on, then create 
MAPI.Session on the secondary thread and set Session.MAPIOBJECT to that from 
the main thread.
The very first thread in a process that calls MAPIInitialize is assumed to 
be the main thread from the MAPI point of view. MAPI uses it to dispatch 
notifications etc.
The fact that a book demonstrates how to use CDO 1.21 in .Net does not mean 
MS supports that :-)
-- 
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool
-
"Cosmin Onea"  wrote in message 
news:uzbBzLuxIHA.5520@TK2MSFTNGP06.phx.gbl...
> If I don't do session = new MAPI.Session() on the main thread I get this:
> Retrieving the COM class factory for component with CLSID 
> {3FA7DEB3-6438-101B-ACC1-00AA00423326} failed due to the following error: 
> 80010106.
>
> If I get the session on the main thread I can't call LogOff on any other 
> thread. Most probably because the main thread is waiting for a key(console 
> application) to exit so the STA the session lives in can't pump messages.
>
> No problems if I do everything on the main thread but that's not what I 
> want because I have  other things to do and eventually the console 
> application will become a windows service.
>
> I read that they don't support 1.21 in .NET but in the same time I read a 
> book that presents .net samples of mapi applications.
>
> Cheers,
> Cosmin
>
> "Dmitry Streblechenko"  wrote in message 
> news:eU$4gGnxIHA.548@TK2MSFTNGP06.phx.gbl...
>> MAPI.Session will call MAPIInitialize internally.
>> What is the exact error that you get?
>> You do know that MS does not support CDO 1.21 from .Net, right?
>>
>> -- 
>> Dmitry Streblechenko (MVP)
>> http://www.dimastr.com/
>> OutlookSpy  - Outlook, CDO
>> and MAPI Developer Tool
>> -
>> "Cosmin Onea"  wrote in message 
>> news:ec5FIRlxIHA.2208@TK2MSFTNGP04.phx.gbl...
>>> Hi,
>>>
>>> I'm trying to use MAPI in a windows service but I've got the 
>>> multithreading problem when trying to use the session on a separate 
>>> thread(timer tick event). If I run everything on the main thread 
>>> (STAThread) everything works great.
>>>
>>> In the documentation it says that MAPIInitialize() should be called on 
>>> each thread you intend to use mapi in. How can I do this from .NET? What 
>>> is the coresponding method in .NET?
>>>
>>> I get the errors when I try to create a session instance like:
>>> objSession = new MAPI.Session()
>>>
>>> This works in the main thread but if I do that again on any other thread 
>>> it crashes. I tried to cache the session object in the main thread and 
>>> reuse it everywhere but objSession.LogOff() get in an infinite loop 
>>> internally.
>>>
>>> Thanks,
>>> Cosmin
>>>
>>
>>
>
>
date: Thu, 5 Jun 2008 09:51:14 -0700   author:   Dmitry Streblechenko

Re: MAPI in mutithreading environments   
If I just create the session on the main thread without logging on on the 
other thread I do
Dim objSession As MAPI.Session = New MAPI.Session
objSession.MAPIOBJECT = MAPISession.GetSession.MAPIOBJECT  /////ERRROR

[Collaboration Data Objects - [MAPI_E_NOT_INITIALIZED(80040605)]]

If I log on on the main thread, I dont really want to do that though, I get
Dim objSession As MAPI.Session = New MAPI.Session
objSession.MAPIOBJECT = MAPISession.GetSession.MAPIOBJECT
objSession.Logon(ProfileInfo:=mbox.Server & vbLf & mbox.Alias) //////ERROR

[Collaboration Data Objects - [MAPI_E_LOGON_FAILED(80040111)]]

I get this because I try to log on again on another server using the same 
mapi session.
The requirement for my app is: I'm given a list of mailboxes(email, alias, 
server, etc) loop through them and connect to the corresponding server and 
get all the unread messages.

If this is not possible with MAPI, and given the fact that MAPI is not 
supported how else can I do it?

Thanks,
Cosmin


"Dmitry Streblechenko"  wrote in message 
news:uhjSfxyxIHA.1936@TK2MSFTNGP04.phx.gbl...
> The error is RPC_E_CHANGED_MODE.
> You can create a session on the main thread, log on, then create 
> MAPI.Session on the secondary thread and set Session.MAPIOBJECT to that 
> from the main thread.
> The very first thread in a process that calls MAPIInitialize is assumed to 
> be the main thread from the MAPI point of view. MAPI uses it to dispatch 
> notifications etc.
> The fact that a book demonstrates how to use CDO 1.21 in .Net does not 
> mean MS supports that :-)
> -- 
> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy  - Outlook, CDO
> and MAPI Developer Tool
> -
> "Cosmin Onea"  wrote in message 
> news:uzbBzLuxIHA.5520@TK2MSFTNGP06.phx.gbl...
>> If I don't do session = new MAPI.Session() on the main thread I get this:
>> Retrieving the COM class factory for component with CLSID 
>> {3FA7DEB3-6438-101B-ACC1-00AA00423326} failed due to the following error: 
>> 80010106.
>>
>> If I get the session on the main thread I can't call LogOff on any other 
>> thread. Most probably because the main thread is waiting for a 
>> key(console application) to exit so the STA the session lives in can't 
>> pump messages.
>>
>> No problems if I do everything on the main thread but that's not what I 
>> want because I have  other things to do and eventually the console 
>> application will become a windows service.
>>
>> I read that they don't support 1.21 in .NET but in the same time I read a 
>> book that presents .net samples of mapi applications.
>>
>> Cheers,
>> Cosmin
>>
>> "Dmitry Streblechenko"  wrote in message 
>> news:eU$4gGnxIHA.548@TK2MSFTNGP06.phx.gbl...
>>> MAPI.Session will call MAPIInitialize internally.
>>> What is the exact error that you get?
>>> You do know that MS does not support CDO 1.21 from .Net, right?
>>>
>>> -- 
>>> Dmitry Streblechenko (MVP)
>>> http://www.dimastr.com/
>>> OutlookSpy  - Outlook, CDO
>>> and MAPI Developer Tool
>>> -
>>> "Cosmin Onea"  wrote in message 
>>> news:ec5FIRlxIHA.2208@TK2MSFTNGP04.phx.gbl...
>>>> Hi,
>>>>
>>>> I'm trying to use MAPI in a windows service but I've got the 
>>>> multithreading problem when trying to use the session on a separate 
>>>> thread(timer tick event). If I run everything on the main thread 
>>>> (STAThread) everything works great.
>>>>
>>>> In the documentation it says that MAPIInitialize() should be called on 
>>>> each thread you intend to use mapi in. How can I do this from .NET? 
>>>> What is the coresponding method in .NET?
>>>>
>>>> I get the errors when I try to create a session instance like:
>>>> objSession = new MAPI.Session()
>>>>
>>>> This works in the main thread but if I do that again on any other 
>>>> thread it crashes. I tried to cache the session object in the main 
>>>> thread and reuse it everywhere but objSession.LogOff() get in an 
>>>> infinite loop internally.
>>>>
>>>> Thanks,
>>>> Cosmin
>>>>
>>>
>>>
>>
>>
>
>
date: Fri, 6 Jun 2008 10:32:26 +0100   author:   Cosmin Onea

Re: MAPI in mutithreading environments   
Cosmin,

to get rid of the error 80010106, you must make your thread is STA:

            _myThread = new Thread(new ThreadStart(DoSomething));
            _myThread.SetApartmentState(ApartmentState.STA);
            _myThread.Start();

If that's the case, you can create the sessionpointer in the thread
itself instead of the main thread.

Regards,
Alex
date: Fri, 6 Jun 2008 03:25:23 -0700 (PDT)   author:   unknown

Re: MAPI in mutithreading environments   
Why do you set the MAPIOBJECT property *before* calling Logon?
As a rule of thumb, since EX provider uses the identity of the current 
Windows (process) user to authenticate with Exchange, you must run your code 
as the user specified in the call to Logon (who owns the mailbox in 
question). In other words, connecting to different mailboxes simultaneously 
won't work with MAPI.
On the Extended MAPI level, you could connect to the current (admin) user 
mailbox first, then open other users' mailboxes using IExchangeManageServer, 
but CDO 1.21 won' let you do that.
<plug>You can try Redemption for that - call RDOSession.LogonExchangeMailbox 
for the current (admin) user, you can then open other mailboxes using 
RDOSession.Stores.GetSharedMailbox. You could log to the admin's mailbox on 
the main thread, but open other mailboxes on the secondary thread by 
creating a new instance of RDOSession (to make sure MAPI gets initialized), 
setting RDOSessioon.MAPIOBJECT to that from the main thread, then opening 
other user's mailbox using  RDOSession.Stores.GetSharedMailbox.
</plug>

-- 
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool
-
"Cosmin Onea"  wrote in message 
news:O446Bi7xIHA.1436@TK2MSFTNGP05.phx.gbl...
> If I just create the session on the main thread without logging on on the 
> other thread I do
> Dim objSession As MAPI.Session = New MAPI.Session
> objSession.MAPIOBJECT = MAPISession.GetSession.MAPIOBJECT  /////ERRROR
>
> [Collaboration Data Objects - [MAPI_E_NOT_INITIALIZED(80040605)]]
>
> If I log on on the main thread, I dont really want to do that though, I 
> get
> Dim objSession As MAPI.Session = New MAPI.Session
> objSession.MAPIOBJECT = MAPISession.GetSession.MAPIOBJECT
> objSession.Logon(ProfileInfo:=mbox.Server & vbLf & mbox.Alias) //////ERROR
>
> [Collaboration Data Objects - [MAPI_E_LOGON_FAILED(80040111)]]
>
> I get this because I try to log on again on another server using the same 
> mapi session.
> The requirement for my app is: I'm given a list of mailboxes(email, alias, 
> server, etc) loop through them and connect to the corresponding server and 
> get all the unread messages.
>
> If this is not possible with MAPI, and given the fact that MAPI is not 
> supported how else can I do it?
>
> Thanks,
> Cosmin
>
>
> "Dmitry Streblechenko"  wrote in message 
> news:uhjSfxyxIHA.1936@TK2MSFTNGP04.phx.gbl...
>> The error is RPC_E_CHANGED_MODE.
>> You can create a session on the main thread, log on, then create 
>> MAPI.Session on the secondary thread and set Session.MAPIOBJECT to that 
>> from the main thread.
>> The very first thread in a process that calls MAPIInitialize is assumed 
>> to be the main thread from the MAPI point of view. MAPI uses it to 
>> dispatch notifications etc.
>> The fact that a book demonstrates how to use CDO 1.21 in .Net does not 
>> mean MS supports that :-)
>> -- 
>> Dmitry Streblechenko (MVP)
>> http://www.dimastr.com/
>> OutlookSpy  - Outlook, CDO
>> and MAPI Developer Tool
>> -
>> "Cosmin Onea"  wrote in message 
>> news:uzbBzLuxIHA.5520@TK2MSFTNGP06.phx.gbl...
>>> If I don't do session = new MAPI.Session() on the main thread I get 
>>> this:
>>> Retrieving the COM class factory for component with CLSID 
>>> {3FA7DEB3-6438-101B-ACC1-00AA00423326} failed due to the following 
>>> error: 80010106.
>>>
>>> If I get the session on the main thread I can't call LogOff on any other 
>>> thread. Most probably because the main thread is waiting for a 
>>> key(console application) to exit so the STA the session lives in can't 
>>> pump messages.
>>>
>>> No problems if I do everything on the main thread but that's not what I 
>>> want because I have  other things to do and eventually the console 
>>> application will become a windows service.
>>>
>>> I read that they don't support 1.21 in .NET but in the same time I read 
>>> a book that presents .net samples of mapi applications.
>>>
>>> Cheers,
>>> Cosmin
>>>
>>> "Dmitry Streblechenko"  wrote in message 
>>> news:eU$4gGnxIHA.548@TK2MSFTNGP06.phx.gbl...
>>>> MAPI.Session will call MAPIInitialize internally.
>>>> What is the exact error that you get?
>>>> You do know that MS does not support CDO 1.21 from .Net, right?
>>>>
>>>> -- 
>>>> Dmitry Streblechenko (MVP)
>>>> http://www.dimastr.com/
>>>> OutlookSpy  - Outlook, CDO
>>>> and MAPI Developer Tool
>>>> -
>>>> "Cosmin Onea"  wrote in message 
>>>> news:ec5FIRlxIHA.2208@TK2MSFTNGP04.phx.gbl...
>>>>> Hi,
>>>>>
>>>>> I'm trying to use MAPI in a windows service but I've got the 
>>>>> multithreading problem when trying to use the session on a separate 
>>>>> thread(timer tick event). If I run everything on the main thread 
>>>>> (STAThread) everything works great.
>>>>>
>>>>> In the documentation it says that MAPIInitialize() should be called on 
>>>>> each thread you intend to use mapi in. How can I do this from .NET? 
>>>>> What is the coresponding method in .NET?
>>>>>
>>>>> I get the errors when I try to create a session instance like:
>>>>> objSession = new MAPI.Session()
>>>>>
>>>>> This works in the main thread but if I do that again on any other 
>>>>> thread it crashes. I tried to cache the session object in the main 
>>>>> thread and reuse it everywhere but objSession.LogOff() get in an 
>>>>> infinite loop internally.
>>>>>
>>>>> Thanks,
>>>>> Cosmin
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
date: Fri, 6 Jun 2008 10:15:35 -0700   author:   Dmitry Streblechenko

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us