2

これが私のコードです。初めて実行したときはすべて正常に動作します。つまり、HttpNotificationChannel.Find() は null を返します。

しかし、2 回目に実行すると、Find() は適切なものを返しますが、Open() 呼び出しに到達すると、例外がスローされます。Open() は引数を取らないので、これは本当に奇妙です。

私は何を間違っていますか?

  public string ChannelName = "MyAppChannel";
  ...
  NotificationChannel = HttpNotificationChannel.Find(ChannelName);
  if (NotificationChannel == null)
  {
    NotificationChannel = new HttpNotificationChannel(ChannelName);
  }
  NotificationChannel.ChannelUriUpdated += new EventHandler(Channel_ChannelUriUpdated);
  NotificationChannel.HttpNotificationReceived += new EventHandler(NotificationChannel_HttpNotificationReceived);
  NotificationChannel.ErrorOccurred += new EventHandler(Channel_ErrorOccurred);
  NotificationChannel.Open();         // <-- Kaboom here, the 2nd time 

全文とスタックは次のとおりです。

System.ArgumentException: E_INVALIDARG
   at Microsoft.Phone.Notification.SafeNativeMethods.ThrowExceptionFromHResult(Int32 hr, Exception defaultException, NotificationType type)
   at Microsoft.Phone.Notification.HttpNotificationChannel.Open()
   at LiveShare.NotificationManager.Initialize()
   at LiveShare.App..ctor()
   at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
   at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
   at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
   at MS.Internal.TypeProxy.<>c__DisplayClass30.b__2a()
   at MS.Internal.TypeProxy.CreateInstance(UInt32 customTypeId)
   at MS.Internal.FrameworkCallbacks.CreateKnownObject(IntPtr nativeRootPeer, UInt32 customTypeId, String initializationString, IntPtr& nativePeer, UInt32 isCreatedByParser)
   at MS.Internal.FrameworkCallbacks.CreateUnknownObject(String assemblyName, String typeName, IntPtr nativeRootPeer, String initializationString, UInt32& customTypeId, UInt32& coreTypeId, UInt32& typeFlags, IntPtr& nativePeer)
4

2 に答える 2

2

正しい解決策は、成功 したOpen()場合に呼び出さないことです。Find()

于 2011-02-15T16:13:20.790 に答える
1

これは、昨年 4 月に Nick Harrisが説明した CTP に関する文書化された問題と非常によく似ています。

解決策: エミュレーターの起動時に [デバッグ] をクリックした直後にチャネルを開こうとすると、この問題が発生します。解決策は簡単です。呼び出しを行う 2 分前にエミュレーターに与えます。

そうでない場合は、Silverlight Showに関する優れた記事があり、WP7 株価アプリでのプッシュ通知について説明しています。

于 2011-02-04T18:26:19.503 に答える