在调试模式下不呈现控件 [英] Not rendering controls in debug mode

查看:30
本文介绍了在调试模式下不呈现控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 winform 应用程序,在其中我在新线程上调用设置窗口作为 ShowDialog.

I have a winform application in which I invoke a settings window as ShowDialog on a new thread.

当我在调试模式下运行应用程序时,设置表单的 Show() 事件不会触发.我尝试了备用 Load() 事件并且它起作用了.在这个方法中,我填充一个列表(DataGridView)并显示它.当表单呈现时,什么都不显示.它只是一个空白表格.

When I run the application in Debug mode, the settings form's Show() event does not fire. I tried the alternate Load() event and it worked. In this method, am populating a list(DataGridView) and displaying it. When the form renders, nothing shows. Its just a blank form.

但是,对于相同的代码,当我在没有调试的情况下运行它(ctrl + F5)时,会触发 Show() 方法并显示列表.

However, for the same code, when I run it without debug( ctrl + F5), the Show() method is triggered and the list is displayed.

代码是一个庞大框架的一部分,所以,我认为我无法提供足够可理解的衡量标准.

The code is part of a huge framework, so, I don't think I can provide in sufficient understandable measure.

我使用的是 Win7 64 位 m/c.

Am using a Win7 64-bit m/c.

此外,即使我在 spy++ 中检查时,它也没有显示表单中的任何内容 - 因此它没有使用任何控件呈现.也没有为 DEBUG 隔离代码.

Also, even when I checked in spy++, it showed no contents in the form - hence it was not rendered with any controls. No code is isolated for DEBUG either.

为什么会发生这种情况以及哪些设置可能需要更改?

Why does this happen and what setting might need changes?

推荐答案

我觉得解决方案很简单.在 WinForms 编程中,有一种叫做 用户界面线程.这意味着所有与 UI 相关的代码都应该在这个线程上执行.如果您在非 UI 线程上执行 UI 相关代码,您将收到跨线程操作无效"异常或意外行为.

I think the solution is very simple. In WinForms programming there is something called the UI Thread. This means that all UI-related code should be executed on this thread. If you execute UI related code on a non-UI-thread, you either get a 'Cross-thread operation not valid' exception, or unexpected behaviour.

我认为这里的解决方案是在 UI 线程而不是新线程上创建设置窗口.

I think the solution here is to create your settings window on the UI thread instead of a new thread.

这篇关于在调试模式下不呈现控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆