c#后台线程访问前台控件并显示信息示例
//设置为后台线程
Thread th = new Thread(delegate() {
append();
});
th.IsBackground = true;
th.Start();
//在append方法里面需要调用前台控件
public void append(){
// ... 业务处理
this.Invoke(new flushMessage(showMessage), new object[] { row["Code"].ToString(), res });
}
//委托flushMessage和方法showMessage签名必须一致
private delegate void flushMessage(String id, String res);
private void showMessage(String id,String res)
{
if (res == "true")
{
txtMsg.Text += "\t\t\t\t" + id + "\t\t\t\t导入成功\r\n";
}
else
{
txtMsg.Text += "\t\t\t\t" + id + "\t\t\t\t\t导入失败\r\n";
}
}
相关推荐
-
C#实现多线程下载文件的方法
本文实例讲述了C#实现多线程下载文件的方法.分享给大家供大家参考.具体实现方法如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Threading; using System.Net; namespace WfpApp { public class MultiDownload { #region 变量 pri
-
C#中WPF使用多线程调用窗体组件的方法
本文实例讲述了C#中WPF使用多线程调用窗体组件的方法.分享给大家供大家参考.具体如下: Thread thread=new Thread(new ThreadStart(TestThread)); thread.Start(); private void TestThread() { for (int i = 0; i < 11;i++ ) { Thread.Sleep(2000); this.listBox1.Dispatcher.Invoke(new Action(() => { thi
-
C#获取进程或线程相关信息的方法
本文实例讲述了C#获取进程或线程相关信息的方法.分享给大家供大家参考.具体实现方法如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace ConsoleApp { class ProcessDo { /// <summary> /// 获取进程相关信息 /// </summary> pub
-
C#线程池操作方法
本文实例讲述了C#线程池操作方法.分享给大家供大家参考.具体如下: static void Main(string[] args) { //设置线程池中的线程数最大为1000, //第一个为工作者线程,第二个为I/O线程 ThreadPool.SetMaxThreads(1000, 1000); for (int i = 0; i < 10;i ) { ThreadPool.QueueUserWorkItem(new WaitCallback(ShowMessage), string.Forma
-
C#队列Queue多线程用法实例
本文实例讲述了C#队列Queue多线程用法.分享给大家供大家参考.具体分析如下: 这里展示一个例子,供学习使用: private void button_测试Queue结合多线程_Click(object sender, EventArgs e) { Console.WriteLine("初始化队列"); queue = new Queue<string>(); string[] cars = new string[]{"宝马","奔驰&quo
-
C#启动进程的几种常用方法
本文实例讲述了C#启动进程的几种常用方法.分享给大家供大家参考.具体如下: 1.启动子进程,不等待子进程结束 private void simpleRun_Click(object sender, System.EventArgs e) { System.Diagnostics.Process.Start(@"C:\listfiles.bat"); } 2.启动子进程,等待子进程结束,并获得输出 private void runSyncAndGetResults_Click(objec
-
C#实现多线程写入同一个文件的方法
本文实例讲述了C#实现多线程写入同一个文件的方法.分享给大家供大家参考.具体实现方法如下: namespace WfpApp { public partial class Form2 : Form { object obj = new object(); public Form2() { InitializeComponent(); System.Threading.Thread thread; string[] users = new string[] { "zkk", "
-
C#多线程处理多个队列数据的方法
本文实例讲述了C#多线程处理多个队列数据的方法.分享给大家供大家参考.具体实现方法如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Collections; using System.Windows.Forms; namespace ThredProcessQueue { //用于顯示狀態的代理
-
C#停止线程的方法
本文实例讲述了C#停止线程的方法.分享给大家供大家参考.具体实现方法如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WinFormApp { publi
-
C#实现强制关闭当前程序进程
/// <summary> /// 运行DOS命令 /// DOS关闭进程命令(ntsd -c q -p PID )PID为进程的ID /// </summary> /// <param name="command"></param> /// <returns></returns> public static string RunCmd(string command) { //實例一個Process類,啟動一個獨立
随机推荐
- Spring实现文件上传(示例代码)
- CentOS 6.4安装配置LAMP服务器(Apache+PHP5+MySQL)
- Lazy Load 延迟加载图片的jQuery插件中文使用文档
- 一些实用的TAB效果第1/2页
- DataGridView单元格显示多行的设置方法
- PHP输出缓存ob系列函数详解
- Yii列表定义与使用分页方法小结(3种方法)
- Android 启动模式详细介绍
- MySQL中的唯一索引的简单学习教程
- eclipse中运行monkeyrunner脚本之环境搭建(4)
- go解析svn log生成的xml格式的文件
- asp.net 使用SqlBulkCopy极速插入数据到 SQL Server
- VBS教程:函数-Atn 函数
- JS判断表单输入是否为空(示例代码)
- node.js中的forEach()是同步还是异步呢
- Android中利用Xposed框架实现拦截系统方法
- ASP文件中的安全问题
- 深入了解SQL注入
- 在Linux 服务器下修改防火墙允许该端口远程访问的方法
- php中钩子(hook)的原理与简单应用demo示例