.net - Outlook Interop "The RPC server is unavailable" when email is opened -
using outlook interop, have created small app connect outlook inbox , collect 30 emails, display them in grid. when double click on email in grid, open email in outlook.
in app: - open email, minimise it. open another, open fine. - open email, close it. open another, 'the rpc server unavailable. (exception hresult: 0x800706ba)' error.
i noticed when happens, outlook icon in system tray disappears.
i have tried creating new instance of microsoft.office.interop.outlook.application , namespace , adding registry setting found here: http://blogs.msdn.com/b/rgregg/archive/2008/10/27/application-shutdown-changes-in-outlook-2007-service-pack-2-beta.aspx
i running office 2010.
does know how around this?
imports microsoft.office.interop.outlook imports system.runtime.interopservices imports system.reflection public class form1 private m_outlookapplication application 'outlook private m_namespace microsoft.office.interop.outlook.namespace 'outlook's namespace private withevents m_inboxitems items 'all outlook inbox items private withevents m_calendaritems items 'all outlook calendar items private m_outlookinstalled boolean = false 'indicates whether outlook installed on computer private m_emails new list(of outlookinboxemail) 'used store inbox e-mail messages grid view control private m_inboxfolder mapifolder 'outlook inbox folder private m_calendarfolder mapifolder 'outlook calendar private m_explorer explorer 'outlook window explorer private m_name string = string.empty 'the name user connected public sub new() initializecomponent() connecttooutlook() loadinbox() end sub private sub connecttooutlook() m_outlookapplication = new microsoft.office.interop.outlook.application m_namespace = m_outlookapplication.getnamespace("mapi") m_namespace.logon(missing.value, missing.value, false, true) dim connectionmode = m_namespace.exchangeconnectionmode end sub private sub loadinbox() try 'get inbox folder m_inboxfolder = m_namespace.getdefaultfolder(oldefaultfolders.olfolderinbox) 'get inbox messages m_inboxitems = m_inboxfolder.items m_emails.clear() 'display recent messages first m_inboxitems.sort("receivedtime", true) dim numberofemailstoload integer = 30 'set displayed values each message each currentitem object in m_inboxitems dim emailitem = trycast(currentitem, mailitem) if not emailitem nothing 'check whether e-mail if emailitem.messageclass = "ipm.note" 'set email dim inboxemail new outlookinboxemail inboxemail.sendername = emailitem.sendername inboxemail.subject = emailitem.subject inboxemail.receivedtime = emailitem.receivedtime.tostring("dd mmmm hh:mm") inboxemail.body = emailitem.body inboxemail.unread = emailitem.unread inboxemail.email = emailitem m_emails.add(inboxemail) numberofemailstoload = numberofemailstoload - 1 if numberofemailstoload <= 0 exit end if end if end if next if m_explorer nothing try m_explorer = m_outlookapplication.activeexplorer catch ex system.exception end try end if if gridcontrol1.datasource nothing gridcontrol1.datasource = nothing gridcontrol1.datasource = m_emails end if gridcontrol1.refreshdatasource() catch exception system.exception end try end sub ''' <summary> ''' opens email in outlook ''' </summary> ''' <remarks></remarks> private sub openemail() if not gridview1.getfocuseddatasourcerowindex < 0 dim selectedemail = trycast(m_emails(gridview1.getfocuseddatasourcerowindex), outlookinboxemail) if not selectedemail nothing try if process.getprocessesbyname("outlook").count() = 0 end if selectedemail.email.display() selectedemail.unread = false selectedemail.emailimage = my.resources.read_16 catch exception comexception end try gridcontrol1.refreshdatasource() end if end if end sub private sub gridcontrolcalendar_doubleclick(byval sender object, byval e system.eventargs) handles gridcontrol1.doubleclick openemail() end sub end class
after several hours of investigation, when message closed closes outlook it.
the solution check before interacting outlook, outlook open. having timer running every 2 minutes ran same check ensured outlook inbox view created ever 2 minutes out of date if outlook closed.
private sub openemail() if not gridviewinbox.getfocuseddatasourcerowindex < 0 dim selectedemail = trycast(m_emails(gridviewinbox.getfocuseddatasourcerowindex), outlookinboxemail) if not selectedemail nothing try if process.getprocessesbyname("outlook").count() = 0 'if outlook not open.. open m_selectedemail = selectedemail reconnectoutlook() else 'as outlook open, open email selectedemail.email.display() selectedemail.unread = false selectedemail.emailimage = imagelibrary.my.resources.read_16 gridcontrolinbox.refreshdatasource() m_selectedemail = nothing end if catch exception comexception eventlog.write(exception) messagebox.show("could not open email. please start outlook , try again.", "opening email", messageboxbuttons.ok, messageboxicon.information) end try gridcontrolinbox.refreshdatasource() end if end if end sub
the reconnection code...
private sub connecttooutlook() try m_outlookapplication = new microsoft.office.interop.outlook.application m_namespace = m_outlookapplication.getnamespace("mapi") 'start outlook dim connectionmode = m_namespace.exchangeconnectionmode m_namespace.logon(missing.value, missing.value, false, true) 'get name of user m_name = m_outlookapplication.session.currentuser.name m_outlookinstalled = true catch exception system.exception if not exception.message.indexof("class not registered") = -1 'outlook not installed m_outlookinstalled = false eventlog.write(exception) else eventlog.write(exception) end if end try end sub
Comments
Post a Comment