我的代碼:
Imports Microsoft.Office.Interop
Imports OpenQA.Selenium
Imports OpenQA.Selenium.Chrome
Imports System.Text
Imports System.Windows.Threading
Imports UiPath
Imports UiPath.Orchestrator.Extensibility
Imports System.IO
Imports System.Net.NetworkInformation
Imports EASendMail
Imports VB = Microsoft.VisualBasic
Class MainWindow
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
'Dim OutlookApp As New Outlook.Application
Dim OutlookApp As Outlook.Application = GetObject(, "Outlook.Application")
Dim Inbox = OutlookApp.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).Items
AddHandler Inbox.ItemAdd, AddressOf Inbox_ItemAdd
'Inbox.ItemAdd = New Outlook.ItemsEvents_ItemAddEventHandler(AddressOf Inbox_ItemAdd)
'This line does not work, but it works in the C# stack question for some reason
End Sub
Public Sub Inbox_ItemAdd(ByVal Item As Object)
Dim mail As Outlook.MailItem = CType(Item, Outlook.MailItem)
If Item IsNot Nothing Then
MsgBox("Received")
End If
End Sub
End Class
我嘗試將 .ItemAdd 中的處理程式添加到名為 Inbox_ItemAdd 的方法中,并嘗試了來自不同 stackoverflow 問題的解決方案,例如:Inbox.ItemAdd = New Outlook.ItemsEvents_ItemAddEventHandler(AddressOf Inbox_ItemAdd)。
我沒主意了。
問題是即使我使用 AddHandler 也不會觸發 Inbox_ItemAdd。
uj5u.com熱心網友回復:
您應該通過將引發事件的物件存盤在欄位中來保持該物件處于活動狀態:
Class MainWindow
Dim Inbox As Outlook.Items
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
...
Inbox = OutlookApp.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).Items
AddHandler Inbox.ItemAdd, AddressOf Inbox_ItemAdd
End Sub
Public Sub Inbox_ItemAdd(ByVal Item As Object)
...
End Sub
End Class
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/415364.html
標籤:
上一篇:VB.Net資料集行數總是回傳0
