Slow opening of outlook

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

When I open a new outlook email from vb.net, sometimes outlook is very slow
to appear or occasionally outlook freezes completely. I am targeting mixed
office2000/xp environments so I am using the office2000 interop dlls
generated by vs.net by adding office 2000 com reference.

Any one else noticed this problem when targeting office2000/xp mixed
environments? Is there a better, more robust way to do this? Am I better off
using late binding?

Thanks

Regards
 
John,
Are you starting Outlook fresh or is it already running? When Outlook is
already running does the same thing happen?

Does this happen "right away" or after using Outlook from VB.NET for awhile?

Are you using System.Runtime.InteropServices.Marshal.ReelaseComObject on
each Outlook object returned, when you are done with that object?

Are you calling Item.Display to show an item or just connecting and
retrieving & updating information? Does this "slowness" happen with specific
Outlook objects & methods?

Do you have other things running on your computer?

Which version of the OS?

Are you using Exchange Server or internet mode?

Are you getting the "security dialog" that states that someone is accessing
your email? And just not seeing it in time?


In case you don't have it, the following site provides a plethora of
articles on using Outlook from .NET:
http://www.microeye.com/resources/res_outlookvsnet.htm

Using Outlook 2003 with VB.NET & the Office 2003 PIA I have not noticed
Outlook being slow to appear.

Unfortunately I don't have a machine with either office 2000 or Office XP.

Hope this helps
Jay
 
I am using display to allow user to enter the email and then press send
button to send it. I am not using
System.Runtime.InteropServices.Marshal.ReelaseComObject. Is there an example
I can see on how to use it?

Thanks

Regards
 
Hi

Not sure how to relate the access example with outlook. Tried to mimic it
but no luck and same error. Isn't there an outlook example around, creating
a new email then display and then cleanup?

Regards
 
John,
How does that saying go: Give a man a fish he eats for a day, teach a man to
fix he eats for live? :-)

The Access example should show you enough of the Concept of working with
Office Automation & ReleaseComObject when combined with the Outlook VBA Help
you should be able to create a working example! As I find VB6 & VBA examples
come are translated almost 1 for 1, the few exceptions to the rule I find
are easy to remember.
but no luck and same error. Isn't there an outlook example around, creating
a new email then display and then cleanup?
Unfortunately I am not setup to test Outlook 2000 automation with .NET.
However! others have used Outlook 2000 from VB.NET with success, have you
reviewed the info at:

http://www.microeye.com/resources/res_outlookvsnet.htm

There is at least one article that specifically deals specifically with
Outlook 2000!

Here is an example of "creating a new email, then display, and then
cleanup":

Imports System.Runtime.InteropServices
Dim app As New Outlook.Application
Dim ns As Outlook.NameSpace
ns = app.GetNamespace("MAPI")
ns.Logon()
Dim mailItem As Outlook.MailItem
mailItem = DirectCast(app.CreateItem(Outlook.OlItemType.olMailItem),
Outlook.MailItem)
mailItem.Display(False)

Marshal.ReleaseComObject(mailItem)
ns.Logoff()
Marshal.ReleaseComObject(ns)
Marshal.ReleaseComObject(app)
Return

I am checking with my fellow Outlook MVPs on why mailItem.Display(True)
leaves the window on the screen.

Hope this helps
Jay
 
John,
Are you using Word as the Editor in Outlook?

There seems to be a problem closing Word when used as the Editor in Outlook,
try the following code to close Word.

Something like:
Dim app As New Outlook.Application
Dim mailItem As Outlook.MailItem
mailItem = DirectCast(app.CreateItem(Outlook.OlItemType.olMailItem),
Outlook.MailItem)
Dim objInsp As Outlook.Inspector
objInsp = mailItem.GetInspector()

mailItem.Display(True)

Marshal.ReleaseComObject(objInsp)

Marshal.ReleaseComObject(mailItem)
Marshal.ReleaseComObject(app)

Note, the dialog is not displayed modally, but its left open for you to fill
out & send...

Hope this helps
Jay
 
Thanks for that. It works fine the first time but calling the code second
time gives the following error;

Unhandled Exception: System.Reflection.TargetInvocationException: Exception
has been thrown by the target of an invocation. --->
System.Runtime.InteropServices.InvalidComObjectException: COM object that
has been separated from its underlying RCW can not be used.
at Outlook.ApplicationEvents_EventProvider..ctor(Object )

I am using the below code and the error comes on the 'OutlookApp = New
Outlook.Application' line. Any ideas what I am missing?

Thanks

Regards

= Code below =======================

Imports System.Runtime.InteropServices

Public Class clsOfficeWrapper
Private WithEvents OutlookApp As Outlook.Application
Private WithEvents em As Outlook.MailItem

Public Sub NewEmail(ByVal EmailTemplate As String, ByVal SendTo As String)
Dim ns As Outlook.NameSpace

OutlookApp = New Outlook.Application ' <=== This lines give the
exception second time round
ns = OutlookApp.GetNamespace("MAPI")
ns.Logon()

em = DirectCast(OutlookApp.CreateItemFromTemplate(EmailTemplate),
Outlook.MailItem)
.To = SendTo
.Display(False)

Marshal.ReleaseComObject(em)
ns.Logoff()
Marshal.ReleaseComObject(ns)
Marshal.ReleaseComObject(OutlookApp)
End Sub
....

End Class
 
I am not using word as editor.

Thanks

Regards


Jay B. Harlow said:
John,
Are you using Word as the Editor in Outlook?

There seems to be a problem closing Word when used as the Editor in Outlook,
try the following code to close Word.

Something like:
Dim app As New Outlook.Application
Dim mailItem As Outlook.MailItem
mailItem = DirectCast(app.CreateItem(Outlook.OlItemType.olMailItem),
Outlook.MailItem)
Dim objInsp As Outlook.Inspector
objInsp = mailItem.GetInspector()

mailItem.Display(True)

Marshal.ReleaseComObject(objInsp)

Marshal.ReleaseComObject(mailItem)
Marshal.ReleaseComObject(app)

Note, the dialog is not displayed modally, but its left open for you to fill
out & send...

Hope this helps
Jay


http://msdn.microsoft.com/library/d...servicesmarshalclassreleasecomobjecttopic.asp
 
Back
Top