При развертывании
System.NullReferenceException не обработано
Message=NullReferenceException
StackTrace:
at wp7nag.MainViewModel.PushChannel_ChannelUriUpdated(Object sender, NotificationChannelUriEventArgs e)
at Microsoft.Phone.Notification.HttpNotificationChannel.OnDescriptorUpdated(IntPtr blob, UInt32 blobSize)
at Microsoft.Phone.Notification.HttpNotificationChannel.ChannelHandler(UInt32 eventType, IntPtr blob1, UInt32 int1, IntPtr blob2, UInt32 int2)
at Microsoft.Phone.Notification.HttpNotificationChannel.Dispatch(Object threadContext)
at System.Threading.ThreadPool.WorkItem.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadPool.WorkItem.doWork(Object o)
at System.Threading.Timer.ring()
подсвеченный код:
void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
{
AppSettings settings = new AppSettings();
CallWithDispatcher(() =>
{
settings.PushURLSetting = String.Format("Channel Uri Updated, new Received\n");
Uri uri = new Uri((string)settings.URLwpNagSetting + "?cmd=14?&push=" + e.ChannelUri.ToString()); // , UriKind.Relative);
WebClient webClient = new WebClient();
webClient.Credentials = new NetworkCredential((string)settings.UserNameSetting, (string)settings.UserPasswordSetting);
webClient.DownloadStringCompleted += OnRegisterPushCompleted;
webClient.DownloadStringAsync(uri);
});
}
up 06.05.2013 :
Выяснил, что проблемы вызывается тем что между открытием канала и получением урла проходит относительно много времени. Закостылил пустым циклом:
// Try to find the push channel.
pushChannel = HttpNotificationChannel.Find(channelName);
// If the channel was not found, then create a new connection to the push service.
if (pushChannel == null)
{
pushChannel = new HttpNotificationChannel(channelName);
// Register for all the events before attempting to open the channel.
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
pushChannel.Open();
// Bind this new channel for Tile events.
settings.PushURLSetting = String.Format("Push Channel Activated\n");
while (pushChannel.ChannelUri == null)
{
// Wait for receiving Channel URI
}
// DeviceRegister(pushChannel.ChannelUri.ToString());
}
else
{
Немає коментарів:
Дописати коментар