Windows phone 7 为什么HttpNotificationChannel.Open.Exception()会失效?

Windows phone 7 为什么HttpNotificationChannel.Open.Exception()会失效?,windows-phone-7,notifications,argumentexception,Windows Phone 7,Notifications,Argumentexception,这是我的密码。在我第一次运行它时,一切正常,即HttpNotificationChannel.Find()返回null 但是第二次运行它时,Find()返回正确的内容,但是当我调用Open()时,它抛出一个异常。这真的很奇怪,因为Open()不接受任何参数 我做错了什么 public string ChannelName = "MyAppChannel"; ... NotificationChannel = HttpNotificationChannel.Find(ChannelNa

这是我的密码。在我第一次运行它时,一切正常,即HttpNotificationChannel.Find()返回null

但是第二次运行它时,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 
公共字符串ChannelName=“MyAppChannel”;
...
NotificationChannel=HttpNotificationChannel.Find(ChannelName);
如果(NotificationChannel==null)
{
NotificationChannel=新的HttpNotificationChannel(通道名称);
}
NotificationChannel.ChannelUriUpdated+=新事件处理程序(Channel\u ChannelUriUpdated);
NotificationChannel.HttpNotificationReceived+=新事件处理程序(NotificationChannel\u HttpNotificationReceived);
NotificationChannel.ErrorOccursed+=新事件处理程序(Channel_ErrorOccursed);

NotificationChannel.Open();// 这看起来非常类似于去年4月CTP记录的问题

解决方案:如果在emulator启动时几乎在点击调试后立即尝试打开通道,则会出现此问题。解决方案很简单——在打电话之前给模拟器两分钟的时间


如果不是这样,有一篇很好的文章介绍了WP7股票报价应用程序中的推送通知。

正确的解决方案是,如果
Find()
成功,不要调用
Open()

不,这是不同的。如果Find()成功,我想我不应该调用Open()。。。
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)