473,597 Members | 2,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[CDO] MAPI.Session Logoff takes too long

Hi

I am using CDO 1.21 from C# in order to iterate through the entries in a users outlook address book (as OOM was too slow). Basically I take the Name field from each "message" and insert it into a ListBox. I shall paste my code at the end, and describe my problem first

If I call my MAPI.Sessions Logoff method when I have finished using it, then this method takes between 1 and 5 minutes to execute, but after that everything is fine

If I DONT call the MAPI.Sessions Logoff method, then I get my ListBox practically instantly filled and on the screen, but if I move the window or use the scroll bars, the program (and any running instances of Outlook) lock up, and only the task manager can kill them

I have seen this problem mentioned in the newsgroup but without a solution. Here is my code: (please note I use OOM and its PickFolder at the start to get my folders Entry and Store IDs

Object oResult;
MAPI.Message oMsg
MAPI.Messages oMsgs
MAPI.Folder oFolder
MAPI.Session oSession
try
{
// OOM Section to get Folder I
Microsoft.Offic e.Interop.Outlo ok.Application oa = new Microsoft.Offic e.Interop.Outlo ok.ApplicationC lass()
Microsoft.Offic e.Interop.Outlo ok.NameSpace ns = oa.GetNamespace ("mapi")
ns.Logon(Enviro nment.UserName, Missing.Value, true, true)
Microsoft.Offic e.Interop.Outlo ok.MAPIFolder contacts = ns.PickFolder()
Object [] argsLogon = new Object[7];
Object[] argsGetFolder = new Object[2] {contacts.Entry ID, contacts.StoreI D}
contacts = null
ns.Logoff()
ns = null
oa = null

oSession = new MAPI.Session()
argsLogon[0] = Missing.Value; // ProfileNam
argsLogon[1] = Missing.Value; // ProfilePasswor
argsLogon[2] = Missing.Value; // ShowDialo
argsLogon[3] = Missing.Value; // NewSessio
argsLogon[4] = Missing.Value; // ParentWindo
argsLogon[5] = Missing.Value; // NoMai
argsLogon[6] = Missing.Value; // ProfileInf
oSession.GetTyp e().InvokeMembe r("Logon", BindingFlags.In vokeMethod, null, oSession, argsLogon)
// Get folder chosen above in PickFolder
oFolder =
(MAPI.Folder)oS ession.GetType( ).InvokeMember( "GetFolder" , BindingFlags.De fault |BindingFlags.G etProperty, null, oSession, argsGetFolder)

// Get folder name
oResult =
oFolder.GetType ().InvokeMember ("Name", BindingFlags.De fault |BindingFlags.G etProperty, null, oFolder, null)
Console.WriteLi ne("Folder Name : {0}", oResult)
// Get AddressLis
oMsgs =
(MAPI.Messages) oFolder.GetType ().InvokeMember ("Messages", BindingFlags.De fault |BindingFlags.G etProperty, null, oFolder, null)

// Get messages count
int totalMessages =
(int)oMsgs.GetT ype().InvokeMem ber("Count", BindingFlags.De fault |BindingFlags.G etProperty, null, oMsgs, null);
Console.WriteLi ne("Count: {0}", totalMessages)
// Get the first message
oMsg =
(MAPI.Message)o Msgs.GetType(). InvokeMember("G etFirst", BindingFlags.In vokeMethod, null, oMsgs, null)

for(int counter = 1; counter <= totalMessages; counter++
// Get Subject
ListViewItem i = new ListViewItem((s tring) oMsg.GetType(). InvokeMember("S ubject", BindingFlags.De fault |BindingFlags.G etProperty, null, oMsg, null))
// Get each message
oMsg =
(MAPI.Message)o Msgs.GetType(). InvokeMember("G etNext", BindingFlags.In vokeMethod, null, oMsgs, null)
listView1.Items .Add(i)
oSession.Logoff (); // This bit causes problem

// The rest omitted.
Jul 21 '05 #1
4 7185
Cor
Hi Kurt,

It is not my part, but maybe I can help you a little bit, because I know
that there are more CDO 1.21 (and that is all I know about it). And maybe
you are busy with the wrong one.

- CDO.DLL : CDO version 1.2.1
- CDONTS.DLL : CDO version 1.2.1 for Windows NT Server (not the same as CDO
version 1.2.1!)

http://msdn.microsoft.com/library/de...vr_cdo_top.asp

Not much, but you never know if this helps?

Cor
Jul 21 '05 #2
Your code seemed to work okay, on my system.
Please try the following code, and see if things are better:

Russell Mangel
Las Vegas, NV

// Begin Code
MAPI.SessionCla ss oSession = new MAPI.SessionCla ss();
oSession.Logon( System.Environm ent.UserName, System.Reflecti on.Missing.Valu e,
true, true, System.Reflecti on.Missing.Valu e, false,
System.Reflecti on.Missing.Valu e);

// Notice we are not logging into Outlook
Microsoft.Offic e.Interop.Outlo ok.Application oApplication = new
Microsoft.Offic e.Interop.Outlo ok.ApplicationC lass();
Microsoft.Offic e.Interop.Outlo ok.NameSpace oNameSpace =
oApplication.Ge tNamespace("map i");
Microsoft.Offic e.Interop.Outlo ok.MAPIFolder oMAPIFolder =
oNameSpace.Pick Folder();
oNameSpace.Logo ff();

MAPI.Folder oFolder = (MAPI.Folder)oS ession.GetFolde r(oMAPIFolder.E ntryID,
oMAPIFolder.Sto reID);
Console.WriteLi ne(oFolder.Name );

MAPI.Messages oMessages = (MAPI.Messages) oFolder.Message s;
MAPI.Message oMessage =
(MAPI.Message)o Messages.GetFir st(System.Refle ction.Missing.V alue);

while(oMessage != null)
{
Console.WriteLi ne(" Subject: " + oMessage.Subjec t);

// Top of Loop
oMessage = null;
oMessage = (MAPI.Message)o Messages.GetNex t();
}

// Let's time the Logoff() method
int begin = System.Environm ent.TickCount;

oSession.Logoff ();

int end = System.Environm ent.TickCount;

Console.WriteLi ne("{0} milliseconds", (end - begin));

// End Code
Jul 21 '05 #3
Hi Russell,

Repeated runs of this example result the logoff function taking exactly
120 seconds each time. In other examples I have tried it always takes
exactly 60 seconds.

There must be some MS specified timeout value affecting things here.

I have XP Professional with latest updates
Office 2003 with latest updates
Visual Studio 2003 .net
Outlook runs in exchange mode and exchange server is exchange 2000
running on windows server 2000.

I shall continue to experiment.

Thanks

Kurt

Russell Mangel wrote:
Your code seemed to work okay, on my system.
Please try the following code, and see if things are better:

Russell Mangel
Las Vegas, NV

// Begin Code
MAPI.SessionCla ss oSession = new MAPI.SessionCla ss();
oSession.Logon( System.Environm ent.UserName, System.Reflecti on.Missing.Valu e,
true, true, System.Reflecti on.Missing.Valu e, false,
System.Reflecti on.Missing.Valu e);

// Notice we are not logging into Outlook
Microsoft.Offic e.Interop.Outlo ok.Application oApplication = new
Microsoft.Offic e.Interop.Outlo ok.ApplicationC lass();
Microsoft.Offic e.Interop.Outlo ok.NameSpace oNameSpace =
oApplication.Ge tNamespace("map i");
Microsoft.Offic e.Interop.Outlo ok.MAPIFolder oMAPIFolder =
oNameSpace.Pick Folder();
oNameSpace.Logo ff();

MAPI.Folder oFolder = (MAPI.Folder)oS ession.GetFolde r(oMAPIFolder.E ntryID,
oMAPIFolder.Sto reID);
Console.WriteLi ne(oFolder.Name );

MAPI.Messages oMessages = (MAPI.Messages) oFolder.Message s;
MAPI.Message oMessage =
(MAPI.Message)o Messages.GetFir st(System.Refle ction.Missing.V alue);

while(oMessage != null)
{
Console.WriteLi ne(" Subject: " + oMessage.Subjec t);

// Top of Loop
oMessage = null;
oMessage = (MAPI.Message)o Messages.GetNex t();
}

// Let's time the Logoff() method
int begin = System.Environm ent.TickCount;

oSession.Logoff ();

int end = System.Environm ent.TickCount;

Console.WriteLi ne("{0} milliseconds", (end - begin));

// End Code

Jul 21 '05 #4
This makes no sense, if you are connected to Exchange Server, you should
have a Global Address List.
If you send a Message from this Client using Outlook 2003, is the Global
address List available?
If so, then all of the code I sent should run okay.

One, question? How are you handling, the Outlook Security Dialogs?
As you probably know, the Security Dialogs, can be disabled by implementing
a special form in a public folder.

You seem to have a basic configuration problem here.

1. Make certain your client is in the Windows 2000 domain.
2. Login to the client with Administrator priveledges, and create a new
profile.
3. If this fails, you need to try another client Computer, in the domain.

Russell Mangel
Las Vegas, NV

Jul 21 '05 #5

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

Similar topics

0
1317
by: Sandy Beach | last post by:
Hi, I have an app, written in c#, that checks an email inbox (using cdo/mapi) and does some processing. I've written a function "WriteToLogFile (string text, bool onConsole)" that checks whether the logfile exists (creates it if not), appends the text to the file, closes the file and displays it on the console, if required. It uses StreamWriter to accomplish this.
7
4183
by: Ottar | last post by:
I've made a program sorting incomming mail in public folder. The function runs every minute by using the form.timer event. In Access XP it runs for weeks, no problem. Access 2003 runs the same code for 6 hours and stops. I've found the problem to be the Set MySession = CreateObject("MAPI.Session")
0
1404
by: Roger | last post by:
I've got this small vba code Public Sub sendmail() Dim osession As Object Set osession = CreateObject("MAPI.Session") osession.logon "npescan", "", False, True, 0, False ... read stuff... osession.logoff set osession = nothing
4
5493
by: Kurt | last post by:
Hi I am using CDO 1.21 from C# in order to iterate through the entries in a users outlook address book (as OOM was too slow). Basically I take the Name field from each "message" and insert it into a ListBox. I shall paste my code at the end, and describe my problem first If I call my MAPI.Sessions Logoff method when I have finished using it, then this method takes between 1 and 5 minutes to execute, but after that everything is fine If...
0
1124
by: Grahame | last post by:
Hi, I have an app, written in c#, that checks an email inbox (using cdo/mapi) and does some processing. I've written a function "WriteToLogFile (string text, bool onConsole)" that checks whether the logfile exists (creates it if not), appends the text to the file, closes the file and displays it on the console, if required. It uses StreamWriter to accomplish this.
0
2228
by: Chris V | last post by:
Hello, I'm having problems sending MAPI Mail from an ASP.NET applcation (in VB) (which worked fine in traditional asp) When run on our test server, it returns an COMException (0x80010106): ]] exception from MAPI. (from the global.asa when trying to create MAPI session I get a .net exception "Cannot change thread mode after it is set")
6
1990
by: Gary Lee | last post by:
In VB.NET using CDO, I'd like to allow multiple threads to share a single MAPI.Session object. If I declare and instantiate sessions within each thread, I'm OK (although this negates the efficiency I'm looking to add). But when I declare, e.g., Public objSession As MAPI.Session I can't access objSession from a worker thread. Thanks in advance for any advice.
8
2684
by: Li Pang | last post by:
Hi, I used following codes to pass a message item from CDO to Outlook. They worked fine when I used outlook 2000, but get an error of "Specified cast is not valid." when I used Outlook 2003. Anybody has an ideal? Dim outlookMsg AsMicrosoft.Office.Interop.Outlook.MailItem Dim adoMsg As MAPI.Message outlookMsg = Microsoft.Office.Interop.Outlook.Application.Session.GetItemFromID(cdoMsg.ID)
0
1666
by: OSI Mik | last post by:
Hi, Sorry for this question but I can't find information about it. I try to connect to Exchange by MAPI or CDO to create folder in mailbox of some user. I found code like that : Dim objSession As MAPI.Session Set objSession As New MAPI.Session
0
7894
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8044
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8261
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6705
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5847
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5437
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2409
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.