gpt4 book ai didi

c# - 位图图像图像打开事件未在后台代理中触发

转载 作者:太空狗 更新时间:2023-10-29 20:39:28 25 4
gpt4 key购买 nike

如标题所示,当代码在 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
};

一切都在 Dispatcher 线程中运行,我正在尝试加载远程图像(我无法缓存它,因为它是由 php 页)。

有什么提示吗?

编辑:

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

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

还是没有成功。

最佳答案

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

关于c# - 位图图像图像打开事件未在后台代理中触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20825820/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com