BitmapImage的ImageOpened事件未在后台代理中触发

Ste*_*TNT 7 c# events background-agents windows-phone-8

与标题中一样,当代码执行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
};
Run Code Online (Sandbox Code Playgroud)

Everthing正在一个Dispatcher线程中运行,我正在尝试加载远程图像(我无法缓存它,因为它是由php页面生成的动态图像).

任何提示?

编辑:

这是基于@ l3arnon建议的代码:

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

但仍然没有成功.

i3a*_*non 1

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