G
Guest
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("GetFolder", 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("Messages", 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("GetFirst", 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("GetNext", BindingFlags.InvokeMethod, null, oMsgs, null)
listView1.Items.Add(i)
oSession.Logoff(); // This bit causes problem
// The rest omitted.
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("GetFolder", 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("Messages", 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("GetFirst", 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("GetNext", BindingFlags.InvokeMethod, null, oMsgs, null)
listView1.Items.Add(i)
oSession.Logoff(); // This bit causes problem
// The rest omitted.