0

我有一个功能区按钮,出现在 Outlook 的撰写电子邮件表单的 tabNewMailMessage 上,此按钮切换粘在表单侧面的 CustomTaskPane 的可见性。

在正常实践中,一切正常。但是,当从 MS Word 或 Adob​​e Reader 等其他应用程序通过“附加到电子邮件”或“保存并发送”调用撰写电子邮件表单时,该按钮会出现但不再执行任何操作。

我从 MSDN 了解到,在外部调用的情况下,NewInspector 事件显然不会触发。

我还没有找到任何解决这种情况的方法,这里有人知道吗?:(

编辑:此外,我有一个 Global 类(不是 Visual Studio 创建的隐藏 GlobalS 类),其中包含我在整个程序中使用的一些变量。插件也不会加载其中包含的任何内容。很难说实际加载了什么,如果有人有更多信息,请回喊!

再次编辑:测试将字符串放入ThisAddIn 并通过toggleButton 中的messageBox 打印它,但不起作用。如果有人感到困惑,如果单击事件无法执行,则功能区按钮将不会加载,因此外部调用的 Compose 表单似乎会跳过 ThisAddIn 中的所有代码以及任何不是功能区本身的类。

我真的需要帮助来解决这个问题!:(

再次编辑:这是我到目前为止所获得的,ThisAddIn 启动事件不会触发,外部类中的任何属性都不会被读取,但外部方法如 say ThisAddIn.SayHelloWorld() 确实有效。

再次编辑!:

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

        //MessageBox.Show(,"TEST");
        try
        {               
            inspectors = Globals.ThisAddIn.Application.Inspectors;
            inspectors.NewInspector += new InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);

            foreach (Inspector insp in inspectors)
            {
                //insp.
                Inspectors_NewInspector(insp);
            }
        }
        catch (System.Exception ex)
        {
            List<string> lalala = new List<string>();
            lalala.Add(ex.GetType().ToString());
            lalala.Add(ex.Message);
            lalala.Add(ex.StackTrace);
            File.WriteAllLines(@"C:\outdebug",lalala.ToArray());
        }
    }

再次!:

void Inspectors_NewInspector(Inspector Inspect)
    {
        try
        {
            if (Inspect.CurrentItem is MailItem)
            {
                Global.mail = Inspect.CurrentItem;
                Global.inspectorWrappersValue.Add(Inspect, new InspectorWrapper(Inspect, Global.mail));
                //inspectorw
            }
        }
        catch (System.Exception ex)
        {
            List<string> lalala = new List<string>();
            lalala.Add(ex.GetType().ToString());
            lalala.Add(ex.Message);
            lalala.Add(ex.StackTrace);
            lalala.Add(Global.SiteConnectionManager.ToString());
            File.WriteAllText(@"C:\Users\cat\Desktop\outdebug.txt", string.Join("\n", lalala), Encoding.UTF8);
        }
    }
4

1 回答 1

1

对 ThisAddIn.Startup 中的所有代码使用 try/catch 处理程序是个好主意,因为 Outlook 非常积极地处理所有异常,因此如果出现问题,您永远不会知道。

但是,我认为真正引起您问题的是在http://social.msdn.microsoft.com/Forums/en/vsto/thread/60c75274-e15a-4696-afa6-79de8fbd707d讨论的 Outlook 问题。解决方案是创建一个计时器并在它触发时检查是否存在现有的检查器。我在下面的内容应该会有所帮助,但这不是一个完整的解决方案,因为它无法处理 NewInspector 触发并且计时器也指示检查员的情况。因此,您必须添加一些逻辑以确保您不会为检查员添加 2 个任务窗格。

public partial class ThisAddIn
{
    private DispatchTimer _newInspectorStartupTimer;

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        try
        {
            // check for existing explorers and inspectors and
            // set up event handlers for new ones

            // here is how you set up the inspector event handler:
            ThisAddIn.Application.Inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);

            // create a timer.  When the timer fires, check if any
            // Inspector windows currently exist, and add task panes
            // for them if needed.
            _newInspectorStartupTimer = new DispatcherTimer();
            _newInspectorStartupTimer.Interval = TimeSpan.FromSeconds(2.0);
            _newInspectorStartupTimer.Tick += new EventHandler(NewInspectorStartupTimer_Tick);
            _newInspectorStartupTimer.Start();
        }
        catch (System.Exception ex)
        {
            // log the exception type, message, and stack trace here
        }
    }

    private void NewInspectorStartupTimer_Tick(object sender, EventArgs e)
    {
        int inspectorCount = _inspectors.Count;
        if (inspectorCount > 0)
        {
            for (int i = 1; i <= _inspectors.Count; ++i)
            {
                Inspector inspector = _inspectors[i];
                Inspectors_NewInspector(inspector);
            }
        }
    }

    // Inspectors_NewInspector also has a try/catch.  Note that
    // Inspectors_NewInspector will be called multiple times
    // for each inspector, due to the timer.
    private void Inspectors_NewInspector(Inspector inspector)
    {
        try
        {
            // you need to check whether you have already created a
            // task pane for this inspector.  If not, create your
            // task pane here.
        }
        catch (System.Exception ex)
        {
            // log the exception type, message, and stack trace here
        }
    }
于 2011-02-28T00:18:26.170 回答