相关疑难解决方法(0)

程序化按钮单击会抛出'System.StackOverflowException'异常

我在C#.Net中编写了一个WinForms程序,在密码表单中以编程方式单击按钮.

Form1加载并显示Form2为对话框.

如果DialogResult是DialogResult.OK的其他任何东西,应用程序将关闭.

到目前为止,我有一个按钮单击事件,编码如下:

 if (txtpass.Text == "")
            {
                MessageBox.Show("You need to enter a password", "Password", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                txtpass.Focus();
            }
            else
            {
                if (txtpass.Text == "1234")
                {
                    radButton1.DialogResult = DialogResult.OK;
                    radButton1.PerformClick();
                }
                else
                {
                    MessageBox.Show("Password Incorrect", "Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtpass.Text = "";
                    txtpass.Focus();
                }
            }
Run Code Online (Sandbox Code Playgroud)

我用radButton1.PerformClick();,但运行程序给我以下消息:

An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll
Run Code Online (Sandbox Code Playgroud)

我不确定导致此异常的原因是什么.

c# stack-overflow click button simulate

9
推荐指数
1
解决办法
4万
查看次数

如何抑制由我​​无法更改的代码显示的对话框?

我有来自第三方的Inproc COM服务器.如果它捕获特定类型的错误,我调用的函数之一将显示错误消息对话框.问题是我正在尝试批量处理数据,而我使用的数据源导致错误对话框弹出很多.如果它生成了1000个对话框,这不会成为问题,而是它会阻塞,直到您按OK才会返回该功能.

在此输入图像描述

如何禁止显示对话框,或以编程方式按OK?

这是一个调用堆栈的副本,​​因为它正在等待我按OK

    [Managed to Native Transition]  
>   System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason, int pvLoopData) Line 2198 + 0x1e bytes   C#
    System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context) Line 3422 + 0x1b bytes C#
    System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) Line 3306 + 0xc bytes   C#
    System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) Line 1495 + 0x31 bytes    C#
    UniversalDataImporter.exe!UniversalDataImporter.Program.Main() Line 18 + 0x1d bytes C#
    [Native to Managed Transition]  
    [Managed to Native Transition]  
    mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) Line 2023 + 0x18 bytes  C#
    Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x27 bytes  
    mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object …

.net c# com messagebox .net-4.0

8
推荐指数
1
解决办法
7990
查看次数

在没有用户输入的情况下以编程方式拆分MessageBox

我正在使用MessageBox不时为用户弹出警报消息.我的特定应用程序可以设置为远程运行,因此有时用户位于计算机前,有时用户可能不在计算机前几小时甚至几天.有时我会弹出一条警报消息MessageBox但在一段时间后警报不再相关.例如,我弹出一个警告,由于某些标准未得到满足,无法完成任务.几分钟后,该标准得到满足,任务就开始了.这MessageBox已不再适用.

我希望能够以编程方式关闭MessageBox这些消息不再相关的情况.这可能吗?目前我MessageBox使用以下方法在线程中创建我的对象:

new Thread(() => MessageBox.Show("Some text", "Some caption")).Start();
Run Code Online (Sandbox Code Playgroud)

我这样做,以便应用程序可以继续在后台工作,而不会被停止MessageBox.有什么建议?

.net c# messagebox winforms

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

c# ×3

.net ×2

messagebox ×2

.net-4.0 ×1

button ×1

click ×1

com ×1

simulate ×1

stack-overflow ×1

winforms ×1