C# 位图图像';未在后台代理中激发ImageOpen事件

C# 位图图像';未在后台代理中激发ImageOpen事件,c#,events,windows-phone-8,background-agents,C#,Events,Windows Phone 8,Background Agents,如标题所示,在BackgroundAgent中执行代码时不会触发事件,而在我的主应用程序中执行代码时,它工作正常 这是我的密码: var background = new BitmapImage(new Uri(uri), UriKind.Absolute)){ CreateOptions = BitmapCreateOptions.None }; background.ImageFailed += (s, e) => { Debug.WriteLine(e); // No

如标题所示,在
BackgroundAgent
中执行代码时不会触发事件,而在我的主应用程序中执行代码时,它工作正常

这是我的密码:

var background = new BitmapImage(new Uri(uri), UriKind.Absolute)){ CreateOptions = BitmapCreateOptions.None };
background.ImageFailed += (s, e) =>
{
    Debug.WriteLine(e);
    // Nothing happens here so I guess that there's no error in the image loading
};
background.ImageOpened += (s, e) =>
{
    Debug.WriteLine("ImageOpened");
    // This line is never printed no the event is never thrown
};
所有东西都在
调度程序
线程中运行,我试图加载一个远程映像(我无法缓存它,因为它是由
php
页面生成的动态映像)

有什么提示吗

编辑:

以下是基于@l3arnon建议的代码:

var backgroundImage = new BitmapImage { CreateOptions = BitmapCreateOptions.None };
backgroundImage.ImageOpened += (s, e) =>
{
                Debug.WriteLine("ImageOpened");
};
backgroundImage.UriSource = new Uri(uri);

但是仍然没有成功。

我唯一的猜测是,它加载映像的速度太快,以至于您注册事件处理程序的速度太快。
尝试先创建BitmapImage实例,然后设置uri

在哪里向ImageLoaded事件注册事件处理程序?实际上,我说的是
ImageOpened
事件,我刚刚编辑了标题。我正在尝试捕获ImageFailed事件,但它从未为本地文件触发。我用扩展名为
.gif
的文本文件进行了尝试,用不存在的路径进行了尝试。没有什么。可能是你的也没有开火。看到Silverlight目前存在同样的问题,你有什么进展吗?ImageFailed/ImageLoaded未触发的间歇性问题