这个问题很可能曾经(很多次)被提出过,但我无法找到解决方案。
我有一个会发送电子邮件的程序。 代码看起来像这样:
Dim oApp As Interop.Outlook.Application = Nothing
While oApp Is Nothing
Try
oApp = New Interop.Outlook.Application
Catch ex As Exception
oApp = Nothing
Dim result As Integer = MessageBox.Show("Outlook is already running, close Outlook and click OK to continue sending this email or click Cancel to skip sending this email.", "Outlook", MessageBoxButtons.OKCancel)
If result = DialogResult.Cancel Then
Exit Sub
End If
End Try
End While
到目前为止一切顺利。用户被迫关闭outlook以使用outlook应用程序。完成后,我这样做:
Dim eMail As Interop.Outlook._MailItem
eMail = oApp.CreateItem(Interop.Outlook.OlItemType.olMailItem)
'To who?
eMail.To = "person@domain.com"
'Sbuject
eMail.Subject = "Foo"
'Message
Dim message As String = "Bar"
eMail.HTMLBody = message
'Send
eMail.Send()
像魅力一样工作,但是当这个完成时,我在托盘中有一个小图标告诉med正在运行Outlook,如果我尝试打开我的Outlook客户端,我会收到一条消息,表明Outlook已经在运行。在我可以使用客户端之前,我必须单击托盘中的图标才能关闭。如何在发送邮件时从我的代码中关闭此应用程序?
我没有成功地试过这个:
oApp.Quit()
oApp.Application.Quit()
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oApp)
oApp = Nothing
感谢任何帮助。