Windows Mobileのコンソールアプリケーションを使用して、着信メッセージの傍受を処理します。同じコンソールアプリケーションで、パラメーター(string args [])を受け入れ、パラメーターに基づいてメッセージインターセプターを登録します。
InterceptorTypeは列挙型です
static void Main(string[] args)
{
if (args[0] == "Location")
{
addInterception(InterceptorType.Location, args[1],args[2]);
}
}
private static void addInterception(InterceptorType type, string Location, string Number )
{
if (type == InterceptorType.Location)
{
using (MessageInterceptor interceptor = new MessageInterceptor(InterceptionAction.NotifyAndDelete, false))
{
interceptor.MessageCondition = new MessageCondition(MessageProperty.Sender, MessagePropertyComparisonType.Contains, Number, false);
string myAppPath = Assembly.GetExecutingAssembly().GetName().CodeBase;
interceptor.EnableApplicationLauncher("Location", myAppPath);
interceptor.MessageReceived += new MessageInterceptorEventHandler(interceptor_MessageReceived);
}
}
}
static void interceptor_MessageReceived(object sender, MessageInterceptorEventArgs e)
{
//Do something
}
これをコンソールアプリケーションにしたのは、バックグラウンドで実行し続け、着信メッセージを傍受したいからです。
これは初めて正常に動作します。しかし、問題は、後続のインターセプトルールを追加するためにaddInterceptionメソッドを呼び出し続ける必要があることです。これにより、ルールを追加するたびにコンソールアプリケーションが何度も起動します。これを1回だけ実行し、メッセージインターセプタールールを追加するにはどうすればよいですか?