473,394 Members | 1,751 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,394 software developers and data experts.

[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.Office.Interop.Outlook.Application oa = new Microsoft.Office.Interop.Outlook.ApplicationClass( )
Microsoft.Office.Interop.Outlook.NameSpace ns = oa.GetNamespace("mapi")
ns.Logon(Environment.UserName, Missing.Value, true, true)
Microsoft.Office.Interop.Outlook.MAPIFolder contacts = ns.PickFolder()
Object [] argsLogon = new Object[7];
Object[] argsGetFolder = new Object[2] {contacts.EntryID, contacts.StoreID}
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.GetType().InvokeMember("Logon", BindingFlags.InvokeMethod, null, oSession, argsLogon)
// Get folder chosen above in PickFolder
oFolder =
(MAPI.Folder)oSession.GetType().InvokeMember("GetF older", BindingFlags.Default |BindingFlags.GetProperty, null, oSession, argsGetFolder)

// Get folder name
oResult =
oFolder.GetType().InvokeMember("Name", BindingFlags.Default |BindingFlags.GetProperty, null, oFolder, null)
Console.WriteLine("Folder Name : {0}", oResult)
// Get AddressLis
oMsgs =
(MAPI.Messages)oFolder.GetType().InvokeMember("Mes sages", BindingFlags.Default |BindingFlags.GetProperty, null, oFolder, null)

// Get messages count
int totalMessages =
(int)oMsgs.GetType().InvokeMember("Count", BindingFlags.Default |BindingFlags.GetProperty, null, oMsgs, null);
Console.WriteLine("Count: {0}", totalMessages)
// Get the first message
oMsg =
(MAPI.Message)oMsgs.GetType().InvokeMember("GetFir st", BindingFlags.InvokeMethod, null, oMsgs, null)

for(int counter = 1; counter <= totalMessages; counter++
// Get Subject
ListViewItem i = new ListViewItem((string) oMsg.GetType().InvokeMember("Subject", BindingFlags.Default |BindingFlags.GetProperty, null, oMsg, null))
// Get each message
oMsg =
(MAPI.Message)oMsgs.GetType().InvokeMember("GetNex t", BindingFlags.InvokeMethod, null, oMsgs, null)
listView1.Items.Add(i)
oSession.Logoff(); // This bit causes problem

// The rest omitted.
Nov 15 '05 #1
4 5489
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
Nov 15 '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.SessionClass oSession = new MAPI.SessionClass();
oSession.Logon(System.Environment.UserName, System.Reflection.Missing.Value,
true, true, System.Reflection.Missing.Value, false,
System.Reflection.Missing.Value);

// Notice we are not logging into Outlook
Microsoft.Office.Interop.Outlook.Application oApplication = new
Microsoft.Office.Interop.Outlook.ApplicationClass( );
Microsoft.Office.Interop.Outlook.NameSpace oNameSpace =
oApplication.GetNamespace("mapi");
Microsoft.Office.Interop.Outlook.MAPIFolder oMAPIFolder =
oNameSpace.PickFolder();
oNameSpace.Logoff();

MAPI.Folder oFolder = (MAPI.Folder)oSession.GetFolder(oMAPIFolder.EntryI D,
oMAPIFolder.StoreID);
Console.WriteLine(oFolder.Name);

MAPI.Messages oMessages = (MAPI.Messages)oFolder.Messages;
MAPI.Message oMessage =
(MAPI.Message)oMessages.GetFirst(System.Reflection .Missing.Value);

while(oMessage != null)
{
Console.WriteLine(" Subject: " + oMessage.Subject);

// Top of Loop
oMessage = null;
oMessage = (MAPI.Message)oMessages.GetNext();
}

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

oSession.Logoff();

int end = System.Environment.TickCount;

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

// End Code
Nov 15 '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.SessionClass oSession = new MAPI.SessionClass();
oSession.Logon(System.Environment.UserName, System.Reflection.Missing.Value,
true, true, System.Reflection.Missing.Value, false,
System.Reflection.Missing.Value);

// Notice we are not logging into Outlook
Microsoft.Office.Interop.Outlook.Application oApplication = new
Microsoft.Office.Interop.Outlook.ApplicationClass( );
Microsoft.Office.Interop.Outlook.NameSpace oNameSpace =
oApplication.GetNamespace("mapi");
Microsoft.Office.Interop.Outlook.MAPIFolder oMAPIFolder =
oNameSpace.PickFolder();
oNameSpace.Logoff();

MAPI.Folder oFolder = (MAPI.Folder)oSession.GetFolder(oMAPIFolder.EntryI D,
oMAPIFolder.StoreID);
Console.WriteLine(oFolder.Name);

MAPI.Messages oMessages = (MAPI.Messages)oFolder.Messages;
MAPI.Message oMessage =
(MAPI.Message)oMessages.GetFirst(System.Reflection .Missing.Value);

while(oMessage != null)
{
Console.WriteLine(" Subject: " + oMessage.Subject);

// Top of Loop
oMessage = null;
oMessage = (MAPI.Message)oMessages.GetNext();
}

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

oSession.Logoff();

int end = System.Environment.TickCount;

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

// End Code

Nov 15 '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

Nov 15 '05 #5

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

Similar topics

0
by: Nitec Dev | last post by:
Our setup: server1 ASP database running on IIS5, Outlook 2000 and SQL 2000 on Windows 2000. Server2 runs Windows 2000 with Exchange 2000 using CDO 1.2 MAPI Sessions. Clients use IE5/6 and had...
4
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...
0
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...
7
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...
0
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......
0
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...
0
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): ]]...
6
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...
8
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....
0
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...
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: 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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...

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.