我有一個有效的URL,用於嘗試在後臺加載的遠程JPEG。但是我發現在調用BitmapImage()
構造函數之後我再也沒有得到控制權。我的問題是,如果這種方法起作用,或者我應該全力以赴,從NuGet加載BcpAsync項目並開始使用WebClient異步方法?無限等待將遠程圖像加載到後臺代理中的BitmapImage()中
爲它失敗的樣本網址是
http://image.weather.com/images/maps/current/garden_june_720x486.jpg
它是有效的。 .UpdateAsync()
參考它從AppViewModel.Instance
,這裏沒有明確引用它。
這裏的後臺代理:
protected override async void OnInvoke(ScheduledTask task)
{
AppViewModel.LoadData();
await AppViewModel.Instance.RemoteImageProxy.UpdateAsync();
AppViewModel.Instance.ImageUrl = AppViewModel.Instance.RemoteImageProxy.LocalFileUri;
AppViewModel.Instance.UpdateCount++;
PinnedTile.Update();
}
AppViewModel.SaveData();
#if DEBUG
ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(AppViewModel.Instance.BgAgentInterval));
#endif
NotifyComplete();
}
這裏的調用方法:
public Task<double> UpdateAsync() {
LastCheckedTime = DateTime.UtcNow;
CompletionTask = new TaskCompletionSource<double>();
// Not usually called on UI thread, not worth optimizing for that case here.
Deployment.Current.Dispatcher.BeginInvoke(() => { //todo determine whether System.Windows.Deployment.Dispatcher can be called from main app, or just bgAgent.
HelperImageControl = new Image();
HelperImageControl.Loaded += im_Loaded;
HelperImageControl.ImageFailed += im_ImageFailed;
HelperImageControl.ImageOpened += im_ImageOpened;
// breakpoint here
HelperImageControl.Source = new BitmapImage(SourceUri);
// stepping over the function, control does not return here. Nor are any of the above events fired.
});
return CompletionTask.Task; // this will be completed in one of the subsequent control events...
}
您是否在輸出窗口中看到任何異常? –