2009-06-14 2 views
0

Windows Mobile에서 자동 응답 메시지를 보내려고합니다. 처음으로 작동하는 것처럼 보이는 MessageInterceptor 클래스를 사용하고 있습니다. 하지만 초 메시지에는 작동하지 않는 것 같습니다! 무한 루프가 필요한지 확실하지 않습니다. Windows Mobile 개발에 대한 많은 경험이 없으므로 최선의 방법을 제안하십시오.Windows Mobile 응용 프로그램에서 MessageInterceptor가 두 번째로 시작되지 않습니다.

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
using Microsoft.WindowsMobile; 
using Microsoft.WindowsMobile.PocketOutlook; 
using Microsoft.WindowsMobile.PocketOutlook.MessageInterception; 


namespace TextMessage3 
{ 
    public partial class Form1 : Form 
    { 

     protected MessageInterceptor smsInterceptor = null; 

     public Form1() 
     { 
      InitializeComponent(); 
      debugTxt.Text = "Calling Form cs"; 
      //Receiving text message 
      MessageInterceptor interceptor = new MessageInterceptor(InterceptionAction.NotifyandDelete); 
      interceptor.MessageReceived += SmsInterceptor_MessageReceived;     
     } 

     public void SmsInterceptor_MessageReceived(object sender, 
     MessageInterceptorEventArgs e) 
     { 
       SmsMessage msg = new SmsMessage(); 
       msg.To.Add(new Recipient("James", "+16044352345")); 
       msg.Body = "Congrats, it works!"; 
       msg.Send(); 
       //Receiving text message 
       MessageInterceptor interceptor = new MessageInterceptor(InterceptionAction.NotifyAndDelete); 
       interceptor.MessageReceived += SmsInterceptor_MessageReceived; 

     } 



    } 
} 

감사합니다,

답변

5

그것은 개체에 대한 유일한 참조가 떨어져 가고 있기 때문에 당신이 당신의 두 번째 메시지를 받고되기 전에 생성자를 떠나 일단 배치지고 당신의 MessageInteceptor 클래스처럼 보이거나 귀하의 이벤트 처리기. 메시지를받을 때마다 새 객체를 만드는 대신 생성자에서 객체를 만들고 멤버 변수로 설정하면됩니다. 메시지가 수신 될 때마다 SmsInterceptor_MessageReceived 함수가 호출되어야합니다.

public partial class Form1 : Form 
    { 

     protected MessageInterceptor smsInterceptor = null; 

     public Form1() 
     { 
      InitializeComponent(); 
      debugTxt.Text = "Calling Form cs"; 
      //Receiving text message 
      this.smsInterceptor = new MessageInterceptor(InterceptionAction.NotifyandDelete); 
      this.smsInterceptor.MessageReceived += this.SmsInterceptor_MessageReceived;     
     } 

     public void SmsInterceptor_MessageReceived(object sender, 
     MessageInterceptorEventArgs e) 
     { 
       SmsMessage msg = new SmsMessage(); 
       msg.To.Add(new Recipient("James", "+16044352345")); 
       msg.Body = "Congrats, it works!"; 
       msg.Send(); 
     } 
    } 
관련 문제