Form.ShowDialog(this)
有时遇到一种情况,.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)的更多相关文章
- 知道Form.Show()和Form.ShowDialog()的区别吗
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:知道Form.Show()和Form.ShowDialog()的区别吗.
- form.Show()和form.ShowDialog()的区别、新建一个form和MessageBox.Show()的常见用法
一:form.Show()和form.ShowDialog()的区别 a. 任何窗体(派生于基类Form的类),都可以以两种方式进行显示. //非模式窗体From qform=new Form();q ...
- 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 ...
- Application.Run()和Form.Show()以及Form.ShowDialog()
ShowDialog()弹出模式化的窗体 Show()弹出非模式化的窗体 模式窗体,在关闭或隐藏前无法切换到主窗体. 非模式窗体,变换焦点使不必关闭窗体 总结:显示重要的信息,还是用模式窗体,如删除文 ...
- Waiting Processed Cancelable ShowDialog
namespace ConsoleApplication { using System; using System.Threading; using Microshaoft; /// <summ ...
- C# 窗体位置 Show和ShowDialog(转)
CenterParent 窗体在其父窗体中居中. CenterScreen 窗体在当前显示窗口中居中,其尺寸在窗体大小中指定. Manual 窗体的位置由 Location 属性确定. Windows ...
- C# 非模式窗体show()和模式窗体showdialog()的区别(转)
对话框不是模式就是无模式的.模式对话框,在可以继续操作应用程序的其他部分之前,必须被关闭(隐藏或卸载).例如,如果一个对话框,在可以切换到其它窗 体或对话框之前要求先单击“确定”或“取消”,则它就是模 ...
- C#学习笔记——Show()与ShowDialog()的区别
用Show()调用的窗体不会返回任何值,在使用form.Show()显示form以后,会马上继续执行form.Show()后面的语句.而用ShowDialog()调用的窗体会返回一个DialogRes ...
- show()与showDialog()的区别
A.WinForm中窗体显示 显示窗体可以有以下2种方法: Form.ShowDialog方法 (窗体显示为模式窗体) Form.Show方法 (窗体显示为无模式窗体) 2者具体区别如下: 1.在 ...
随机推荐
- blurImage做图片模糊处理报错free(): invalid next size
$image = new Imagick($url); $image->blurImage($x, $y); 调用blurImage($x, $y)函数报错: 原因是:原来的图片是CMYK的是印 ...
- servlet 3.0特性说明
Servlet 3.0 作为 Java EE 6 规范体系中一员,随着 Java EE 6 规范一起发布.该版本在前一版本(Servlet 2.5)的基础上提供了若干新特性用于简化 Web 应用的开发 ...
- Windows下编译memcached-1.4.5(32bit和64bit)
1.简介 Memcached 是一个高性能的分布式内存对象缓存系统.它通过将数据缓存在内存中来减少对数据库和文件系统的访问,减轻数据库及操作系统的负担,提高应用系统的速度. 目前已经很多系统应用了me ...
- [翻译] FMDB
FMDB https://github.com/ccgus/fmdb This is an Objective-C wrapper around SQLite: http://sqlite.org/ ...
- [翻译] The Amazing Audio Engine
The Amazing Audio Engine https://github.com/TheAmazingAudioEngine/TheAmazingAudioEngine The Amazing ...
- DTree的改进与使用经验
1.dtree.js源码 function Node(id, pid, name, url, title, target, icon, iconOpen, open) { this.id = id; ...
- 第九章 Redis过期策略
注:本文主要参考自<Redis设计与实现> 1.设置过期时间 expire key time(以秒为单位)--这是最常用的方式 setex(String key, int seconds, ...
- C#一个FTP操作封装类FTPHelper
参考了网上一些代码,作了一些调整优化. 001 using System; 002 using System.Collections.Generic; 003 using System.Linq; 0 ...
- ifconfig无输出的解决办法
问题 执行 ifconfig 命令无任何报错,也无任何输出信息 [root@linuxprobe ~]# ifconfig [root@linuxprobe ~]# 排错 1. 检查PATH变量 [r ...
- linux loop device介绍
在Linux中,有一种特殊的块设备叫loop device,这种loop device设备是通过影射操作系统上的正常的文件而形成的虚拟块设备.因为这种设备的存在,就为我们提供了一种创建一个存在于其他文 ...