对Exchange中的公用文件夹ItemAdd事件 [英] ItemAdd event on a public folder on Exchange

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

问题描述

我有附加的事件处理程序公用文件夹的 ItemAdd 事件的一个问题。




问题是一些
成功的来电之后,事件处理程序停止被调用。




代码实在是微不足道。我有一个的ThisAddIn 类,它创建一个对象反过来重视在其构造的 ItemAdd 事件的函数。该功能只弹出一个消息框。



请点我在正确的方向。我只是不明白的地方寻找错误。



感谢你在前进,
阿纳托利



下面是测试代码中,我尝试运行:

 公共部分类的ThisAddIn 
{
内部静态Outlook.Folder posts_folder = NULL;
私有静态测试吨;

私人无效ThisAddIn_Startup(对象发件人,发送System.EventArgs)
{

T =新的测试();
}
{

类测试
{
公开测试()
{
System.Windows.Forms.MessageBox。显示(附加...);
ThisAddIn.posts_folder.Items.ItemAdd + =新Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
}
无效Items_ItemAdd(对象的项目)
{
System.Windows.Forms.MessageBox.Show((项目作为Outlook.PostItem).Subject);
}
}


解决方案

连续谷歌上搜索他的工作的。我发现如何解决这个问题。它似乎我不是谁体验它是唯一一个



我添加了参考我想跟踪的全球范围内的文件夹的项目集合:



 内部静态类STOR 
{
公共静态Outlook.Items我;
}

公共部分类的ThisAddIn
{
内部静态Outlook.Folder posts_folder = NULL;

私人无效ThisAddIn_Startup(对象发件人,发送System.EventArgs)
{
//查找posts_folder代码省略

stor.i = posts_folder.Items;
stor.i.ItemAdd + =新Outlook.ItemsEvents_ItemAddEventHandler(Posts_Add);
}

静态无效Posts_Add(对象的项目)
{
System.Windows.Forms.MessageBox.Show(新项目);
}
{

现在它按预期工作。 Alhough我不明白所有的细节,他们说,这是一个垃圾回收问题。我的事件处理程序最终被扔进垃圾堆。在全球范围内的项目集合的参考防止这种情况的发生。


I have a problem with attaching an event handler to an ItemAdd event of a public folder.

The problem is the event handler stops being called after a few successful calls.

The code is trivial. I have a ThisAddIn class which creates an object which in turn attaches a function to the ItemAdd event in its constructor. The function just pops up a messagebox.

Please point me in the right direction. I simply don't understand where to look for the error.

Thank you in advance, Anatoly

Here is the test code I try to run:

public partial class ThisAddIn
{
    internal static Outlook.Folder posts_folder = null;
    private static test t;

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {

        t = new test();
    }
{

class test
{
    public test()
    {
        System.Windows.Forms.MessageBox.Show("Attaching...");
        ThisAddIn.posts_folder.Items.ItemAdd +=new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
    }
    void Items_ItemAdd(object Item)
    {
        System.Windows.Forms.MessageBox.Show((Item as Outlook.PostItem).Subject);
    }
}

解决方案

Continuous googling did its job. I found how to resolve the issue. It appears I am not the only one who experience it.

I added the reference to Items collection of the folder I want to track to the global scope:

internal static class stor
{
    public static Outlook.Items i;
}

public partial class ThisAddIn
{
    internal static Outlook.Folder posts_folder = null;

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        // the code for finding a posts_folder is omitted

        stor.i = posts_folder.Items;
        stor.i.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(Posts_Add);
    }

    static void Posts_Add(object Item)
    {
        System.Windows.Forms.MessageBox.Show("New item");
    }
{

Now it works as expected. Alhough I do not understand all the details they say it is a garbage collection issue. My event handler eventually was thrown into the garbage. The reference to the Items collection on the global scope prevents this from happening.

这篇关于对Exchange中的公用文件夹ItemAdd事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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