2017-12-01 9 views
0

다음 VSTO 추가 기능 코드가 있습니다. 그러나 items_ItemAdd() 메서드는 영향을받지 않습니다.VSTO ItemAdd 이벤트가 실행되지 않습니다.

public partial class ThisAddIn 
    { 
     Outlook.NameSpace outlookNameSpace; 
     Outlook.MAPIFolder inbox; 
     Outlook.Items items; 

     private void ThisAddIn_Startup(object sender, System.EventArgs e) 
     { 
      outlookNameSpace = this.Application.GetNamespace("MAPI"); 
      Debug.WriteLine("Starting Add-In"); 
      inbox = outlookNameSpace.GetDefaultFolder(
        Microsoft.Office.Interop.Outlook. 
        OlDefaultFolders.olFolderInbox); 
      items = inbox.Items; 
      items.ItemAdd += 
       new Outlook.ItemsEvents_ItemAddEventHandler(items_ItemAdd); 
      Debug.WriteLine("Started Add-In"); 
     } 

     void items_ItemAdd(object Item) 
     { 
      Debug.WriteLine("New email arrived."); 
      Outlook.MailItem mail = (Outlook.MailItem)Item; 
      if (Item != null) 
      { 
       if (mail.MessageClass == "IPM.Note") 
       { 
        string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "example.html"); 
        Debug.WriteLine("Saving to " + path); 
        mail.SaveAs(path, Outlook.OlSaveAsType.olHTML); 
       } 
      } 
     } 

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

     #region VSTO generated code 

     /// <summary> 
     /// Required method for Designer support - do not modify 
     /// the contents of this method with the code editor. 
     /// </summary> 
     private void InternalStartup() 
     { 
      this.Startup += new System.EventHandler(ThisAddIn_Startup); 
      this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); 
     } 

     #endregion 
    } 

이 예제는 MSDN과 매우 비슷합니다. 아이디어가 있습니까? Visual Studio 2010에서 VSTO Outlook 2007 추가 기능을 사용하여이를 개발하고 있습니다. 디버그 모드에서이 문제를 시도했지만 이벤트가 실행되지 않습니다. Outlook 2010을 내 dev 컴퓨터에 설치했습니다.

답변

0

나는 일을 무슨 짓을

추가했다 ... 그 유일한 대답은 인터넷에 모든 곳에서 제안 된 것으로 보인다 쓰레기 수거를 해결하기 위해 클래스 수준에서 일부 멤버를 선언에도 불구하고 작동하도록 ItemsEvents_ItemAddEventHandler를 가져올 수 없습니다
System.Threading.Timer timer = null; 
timer = new System.Threading.Timer((obj) => 
{ 
    ItemAddEventHandler(); 
    timer.Dispose(); 
}, null, 3000, System.Threading.Timeout.Infinite); 

내가 더 신뢰할 수 NewMailEx 이벤트를 발견했지만 그것에서 이벤트를 수신 에 폴더를 선택 할 수없는 등의 단점이있어 가지고 이벤트를 부착시 약간의 시간 지연은 아래 그림과 같이. 누군가가 도움이 되었으면 좋겠지 만 깨끗한 해결책은 아닙니다. 어떤 조치로든.