2009-06-14 19 views
0

Windows Mobileで自動メッセージ返信を取得しようとしています。私は初めて動作するように見えるMessageInterceptorクラスを使用しています。しかし、それは秒メッセージのために働くようではありません!私は無限ループを持つ必要があるかどうかはわかりません。私はWindows Mobile開発の経験がたくさんありませんので、最善の方法をお勧めします。Windows MobileアプリケーションでMessageInterceptorが2度目に起動しない

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; 

     } 



    } 
} 

オブジェクトへの参照のみを使用して、コンストラクタを離れると離れて行くのか、されているので、あなたの第2のメッセージを取得している前に、あなたのMessageInteceptorクラスが配置されつつあるように見えますおかげで、

タム

答えて

5

あなたのイベントハンドラ。メッセージを受け取るたびに新しいオブジェクトを作成するのではなく、コンストラクターでメンバーを作成し、それをメンバー変数に設定するだけです。メッセージが受信されるたびに、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(); 
     } 
    } 
関連する問題