有时遇到一种情况,.ShowDialog()不显示。也不报错。例如以下:

<span style="font-size:14px;"> private void button1_Click(object sender, EventArgs e)
{
Thread thread = new Thread(show);
thread.Start();
}
void show()
{
Control.CheckForIllegalCrossThreadCalls = false;
//this.Invoke(new Action(() =>
//{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{ }
//}));
}</span>

原因分析:这属于线程间操作的一种异常。界面呈现和新创建的thread分开在两个线程中。在thread线程中

不可以进行界面呈现,即显示.ShowDialog();

解决方法:1:加入參数this。

.ShowDialog(IWin32Window owner);    //owner:表示将拥有模式对话框的顶级窗体

<span style="font-size:14px;"> private void button1_Click(object sender, EventArgs e)
{
Thread thread = new Thread(show);
thread.Start();
}
void show()
{
Control.CheckForIllegalCrossThreadCalls = false;
//this.Invoke(new Action(() =>
//{
if (saveFileDialog1.ShowDialog(this) == DialogResult.OK)
{ }
//}));
}</span>

2:使用Invoke

        private void button1_Click(object sender, EventArgs e)
{
Thread thread = new Thread(show);
thread.Start();
}
void show()
{
// Control.CheckForIllegalCrossThreadCalls = false;
this.Invoke(new Action(() =>
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{ }
}));
}

Form.ShowDialog(this)的更多相关文章

  1. 知道Form.Show()和Form.ShowDialog()的区别吗

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:知道Form.Show()和Form.ShowDialog()的区别吗.

  2. form.Show()和form.ShowDialog()的区别、新建一个form和MessageBox.Show()的常见用法

    一:form.Show()和form.ShowDialog()的区别 a. 任何窗体(派生于基类Form的类),都可以以两种方式进行显示. //非模式窗体From qform=new Form();q ...

  3. Form.ShowDialog和Form.DialogResult

    The dialog result of a form is the value that is returned from the form when it is displayed as a mo ...

  4. Application.Run()和Form.Show()以及Form.ShowDialog()

    ShowDialog()弹出模式化的窗体 Show()弹出非模式化的窗体 模式窗体,在关闭或隐藏前无法切换到主窗体. 非模式窗体,变换焦点使不必关闭窗体 总结:显示重要的信息,还是用模式窗体,如删除文 ...

  5. Waiting Processed Cancelable ShowDialog

    namespace ConsoleApplication { using System; using System.Threading; using Microshaoft; /// <summ ...

  6. C# 窗体位置 Show和ShowDialog(转)

    CenterParent 窗体在其父窗体中居中. CenterScreen 窗体在当前显示窗口中居中,其尺寸在窗体大小中指定. Manual 窗体的位置由 Location 属性确定. Windows ...

  7. C# 非模式窗体show()和模式窗体showdialog()的区别(转)

    对话框不是模式就是无模式的.模式对话框,在可以继续操作应用程序的其他部分之前,必须被关闭(隐藏或卸载).例如,如果一个对话框,在可以切换到其它窗 体或对话框之前要求先单击“确定”或“取消”,则它就是模 ...

  8. C#学习笔记——Show()与ShowDialog()的区别

    用Show()调用的窗体不会返回任何值,在使用form.Show()显示form以后,会马上继续执行form.Show()后面的语句.而用ShowDialog()调用的窗体会返回一个DialogRes ...

  9. show()与showDialog()的区别

    A.WinForm中窗体显示  显示窗体可以有以下2种方法:  Form.ShowDialog方法 (窗体显示为模式窗体) Form.Show方法 (窗体显示为无模式窗体) 2者具体区别如下: 1.在 ...

随机推荐

  1. How to match between physical usb device and its drive letter?

    struct tagDrives { WCHAR letter; WCHAR volume[ BUFFER_SIZE ]; } g_drives[ ]; // WCHAR GetUSBDrive( ) ...

  2. systemtap 用户态调试3

    [root@localhost ~]# cat test.c #include <stdio.h> int main( void) { int a=0; a=fun(10,20); pri ...

  3. highcharts 画图选项配置(待完善------)

    在使用highcharts画图过程中,经常查阅图表选项设置,现将画图过程中设置过的选项收集记录如下留待以后参考: 折线图 <!DOCTYPE html> <html lang=&qu ...

  4. 解决win8内置管理员无法激活此应用

    解决win8内置管理员无法激活此应用 方法/步骤   在运行中输入:“gpedit.msc”,就会启动组策略编辑器.   依次展开“计算机配置”里面的 “Windows设置” “安全设置” “本地策略 ...

  5. Redis持久化RDB和AOF优缺点是什么,怎么实现的?我应该用哪一个?

    原文http://www.ymq.io/2018/03/24/redis/ Redis是一种高级key-value数据库.数据可以持久化,而且支持的数据类型很丰富.有字符串,链表,集 合和有序集合.支 ...

  6. jsondataobjects

    jsondataobjects GITHUB: https://github.com/ahausladen/jsondataobjects.git 跨平台JSON库 Json Data Objects ...

  7. 实现工资的按天统计(X:日期 Y:姓名)

    案例:工人工资按天按班别存入数据库,想实现一根据部门及员工姓名还有日期的汇总表... 汇总表效果如下: 还可以根据XY坐标对应的值查询显示该日期的明细记细 2013-09-06升级(如是当月最多只能显 ...

  8. 深度学习阅读列表 Deep Learning Reading List

    Reading List List of reading lists and survey papers: Books Deep Learning, Yoshua Bengio, Ian Goodfe ...

  9. [置顶] think in java interview-高级开发人员面试宝典(一)

    “生死六重门” 无论你是在职,非在职,高级工程师,工程师,架构师,如果你正在面试阶段,请看完此文! 相信这篇文章对你的职业生涯和阶值观会造成重大的改变! 如果你是一名PM或者是管理者正在物色合适的开发 ...

  10. jquery 返回顶端组件

    自己写了一个基于jquery的返回页面顶端的组件. (function($) { var g; $.backtop = function(options) { extend($.backtop.con ...