BeginInvoke 激活表单

发布于 2024-10-02 09:28:24 字数 408 浏览 0 评论 0原文

我有一个用 C# 编写的 WinForms 应用程序。打开时出现的第一个屏幕是仪表板屏幕,可能需要一些时间才能加载。使用委托上的 BeginInvoke 调用数据加载方法。那部分很好,我的问题是当我想将读取的数据加载到某些网格中时。让我回到 UI 线程的代码看起来像这样,

BeginInvoke(new Action<DashboardDataInfo, int>(LoadDashboardData), data, outbox);

这一切都没有错误地发生。我的问题是仪表板表单将跳到屏幕顶部。如果数据加载花费了足够长的时间,用户可能已经进入应用程序中的另一个(所以这真的很烦人)。除了分配一些 DataGridView 控件的 DataSource 属性之外,LoadDashboardData 方法没有做太多事情。

I have a WinForms application written in C#. The first screen to appear when it opens is a dashboard screen that can take some time to load. The data loading method is called using BeginInvoke on delegate. That part is fine, my problem is when I want to load the read data into some grids. The code to get me back to my UI thread looks like so

BeginInvoke(new Action<DashboardDataInfo, int>(LoadDashboardData), data, outbox);

This all happens without error. My problem is the dashboard Form will jump to the top of the screen. If data loading has taken long enough the user could be already onto another from in the app (so this is really annoying). The LoadDashboardData method doesn't do much besides assign the DataSource property of a few DataGridView controls.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文