Outlook加载项事件问题 [英] Outlook Add-In Event Problem

查看:403
本文介绍了Outlook加载项事件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在使用VSTO 2005 SE创建outllok加载项。我正面临一个问题。我的展望事件没有被解雇。我也使用System Tray Icon类在任务栏中创建Icon。如果我评论创建托盘图标的代码,那么它工作正常。这是我的代码

公共类AddIn

私有Sub ThisAddIn_Startup(ByVal sender As Object,ByVal e As System.EventArgs)处理Me.Startup
调用initializeValue( )
调用initializeEvent()
调用initializeTimer()
结束子

Private Sub initializeValue()
olApp = DirectCast(Application,Outlook.Application)
olNS = olApp.GetNamespace(" MAPI")
olExplorer = olApp.ActiveExplorer
End Sub

Private Sub initializeEvent()
Dim olFolder As Outlook.Folder = Nothing ol Dalendar olCalendarFolder As Outlook.MAPIFolder
Dim olItems As Items
olCalendarFolder = olNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
olFolder = DirectCast(olCalendarFolder,Outlook .Folder)
olItems = olCa lendarFolder.Items

Hello
  I am using VSTO 2005 SE for creating outllok add-in. I am facing a problem. My outlook events are not getting fired. I am also using System Tray Icon class for creating Icon in Task bar. If i comment the code for creating Tray Icon then it is working fine. Here is my code

    Public Class AddIn

    Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
        Call initializeValue()
        Call initializeEvent()
        Call initializeTimer()
    End Sub
   
    Private Sub initializeValue()
        olApp = DirectCast(Application, Outlook.Application)
        olNS = olApp.GetNamespace("MAPI")
        olExplorer = olApp.ActiveExplorer
    End Sub
   
    Private Sub initializeEvent()
        Dim olFolder As Outlook.Folder = Nothing
        Dim olCalendarFolder As Outlook.MAPIFolder
        Dim olItems As Items
        olCalendarFolder = olNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
        olFolder = DirectCast(olCalendarFolder, Outlook.Folder)
        olItems = olCalendarFolder.Items

AddHandler olItems.ItemAdd,AddressOf ApptAdded
AddHandler olItems.ItemChange,AddressOf ApptModified
AddHandler olItems.ItemRemove,AddressOf ApptDelete
olFolder = Nothing
olCalendarFolder =无结束子

        AddHandler olItems.ItemAdd, AddressOf ApptAdded
        AddHandler olItems.ItemChange, AddressOf ApptModified
        AddHandler olItems.ItemRemove, AddressOf ApptDelete
        olFolder = Nothing
        olCalendarFolder = Nothing
    End Sub

私人子附加(ByVal objItem As Object)

结束子

    Private Sub ApptAdded(ByVal objItem As Object)
       
    End Sub

Private Sub ApptModified(ByVal objItem As Object)

    Private Sub ApptModified(ByVal objItem As Object)

End Sub

Private Sub ApptDelete()

    Private Sub ApptDelete()

End Sub

结束类

公共类clsTrayIcon.vb

私有SysTrayIcon As System.Windows.Forms.NotifyIcon
Private AnimIconList As Icon()

Public Sub New()
InitDefaults()
End Sub

    End Sub
   
    End class

   Public Class  clsTrayIcon.vb
    
    Private SysTrayIcon As System.Windows.Forms.NotifyIcon
    Private AnimIconList As Icon()
   
    Public Sub New()
        InitDefaults()
    End Sub

Private Sub InitDefaults()
SysTrayIcon = New System.Windo ws.Forms.NotifyIcon()
objAnimTimer = New System.Windows.Forms.Timer()
objAnimTimer.Interval = 1
SysTrayIcon.Text =" Test Outlook Add-in"
AddHandler objAnimTimer.Tick,AddressOf Me.SysTrayAnimator
Me.SysTrayIcon.Visible = True
End Sub

Public Sub SetIconRange(ByVal IconList As Object())
AnimIconList =新图标(IconList.Length - 1){}
对于i As Integer = 0 To IconList.Length - 1
AnimIconList(i)= IconList(i)
下一页图标= AnimIconList(0)
结束如果终止子

公共属性图标()作为图标
获取回复我.SysTrayIcon.Icon
结束获取设置(ByVal值为图标)
Me.SysTrayIcon.Icon =值
结束设置结束属性
结束类

模块modGblVariable
Public objTrayIcon As new clsTrayIcon()

    Private Sub InitDefaults()
        SysTrayIcon = New System.Windows.Forms.NotifyIcon()
        objAnimTimer = New System.Windows.Forms.Timer()
        objAnimTimer.Interval = 1
        SysTrayIcon.Text = "Test Outlook Add-in"
        AddHandler objAnimTimer.Tick, AddressOf Me.SysTrayAnimator
        Me.SysTrayIcon.Visible = True
    End Sub
   
    Public Sub SetIconRange(ByVal IconList As Object())
        AnimIconList = New Icon(IconList.Length - 1) {}
        For i As Integer = 0 To IconList.Length - 1
            AnimIconList(i) = IconList(i)
        Next
        If IconList.Length > 0 Then
            Icon = AnimIconList(0)
        End If
    End Sub
   
    Public Property Icon() As Icon
        Get
            Return Me.SysTrayIcon.Icon
        End Get
        Set(ByVal value As Icon)
            Me.SysTrayIcon.Icon = value
        End Set
    End Property
End Class

Module modGblVariable 
      Public objTrayIcon As New clsTrayIcon()

Public Sub loadTrayIcon()
Dim objValues As Object
objValues =新对象(4){}
objValues(0)= My.Resources.icon1
objValues(1)= My.Resources.icon2
objValues(2)= My.Resources.icon3
objValues(3)= My.Resources.icon4
objValues(4)= My.Resources.icon5
调用objTrayIcon.SetIconRange(o bjValues)
objValues = Nothing
End Sub终止模块

请大家告诉我为什么会这样?

      Public Sub loadTrayIcon()
          Dim objValues As Object
          objValues = New Object(4) {}
          objValues(0) = My.Resources.icon1
          objValues(1) = My.Resources.icon2
          objValues(2) = My.Resources.icon3
          objValues(3) = My.Resources.icon4
          objValues(4) = My.Resources.icon5
          Call objTrayIcon.SetIconRange(objValues)
          objValues = Nothing
      End Sub
    End Module

Please can anyone tell me why this is happing?

推荐答案

我在这里看到的主要原因是olItems是函数initializeEvent的局部变量,可以在函数调用后进行垃圾收集。将此变量声明为AddIn类的成员变量,这应该有效。
The major reason I see here is that the olItems  is local variable of function initializeEvent, which can be garbage collected after the function call. Declare this variable as Member variable of AddIn class and this should work.


这篇关于Outlook加载项事件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆