문제

C#에서 VSTO를 만들어 Outlook 2007의 Newmailex 이벤트를 연결해야합니다. 그러나 수동 보내기/수신을 할 때 또는받은 편지함에 읽지 않은 메일 만있을 때 때때로 발사되지 않습니다. 메시지가 실제로 도착하기 전에받은 편지함에서 발사되는 것처럼 보입니다.

새로운 메시지를 모니터링하는 더 좋은 방법이 있습니까? 매번 VSTO를 사용하는 itemAdd 또는 NewMailEx 외에?

도움이 되었습니까?

해결책

그 이유는 "GC는 .NET 객체를 수집하여 COM 객체를 Outlook에서 wapr니다)." 솔루션은이 .NET 객체에 대한 참조입니다. 가장 쉬운 방법은 다음과 같습니다.

// this is helper collection.
// there are all wrapper objects
// , which should not be collected by GC
private List<object> holdedObjects = new List<object>();

// hooks necesary events
void HookEvents() {
    // finds button in commandbars
    CommandBarButton btnSomeButton = FindCommandBarButton( "MyButton ");
    // hooks "Click" event
    btnSomeButton.Click += btnSomeButton_Click;
    // add "btnSomeButton" object to collection and
    // and prevent themfrom collecting by GC
    holdedObjects.Add( btnSomeButton );
}

원하는 경우이 (및 기타) 콘크리트 버튼 (또는 다른 물체)에 대한 특별한 필드를 가질 수 있습니다. 그러나 이것은 가장 일반적인 해결책입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top