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.Diagnostics; namespace ConsoleApp { class ProcessDo { /// <summary> /// 获取进程相关信息 /// </summary> pub
-
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#启动进程的几种常用方法.分享给大家供大家参考.具体如下: 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#多线程处理多个队列数据的方法.分享给大家供大家参考.具体实现方法如下: 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.Linq; using System.Text; using System.IO; using System.Threading; using System.Net; namespace WfpApp { public class MultiDownload { #region 变量 pri
-
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類,啟動一個獨立
-
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#线程池操作方法.分享给大家供大家参考.具体如下: 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#停止线程的方法.分享给大家供大家参考.具体实现方法如下: 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
随机推荐
- SQLServer性能优化--间接实现函数索引或者Hash索引
- IIS配置文件的XML格式不正确 applicationHost.config被破坏 恢复解决办法
- 给apache2.2加上mod_encoding模块後 php5.2.0 处理url出现bug
- Pyramid添加Middleware的方法实例
- 基于内核线程的创建、使用和退出以及延时宏的补充说明介绍
- Android中删除文件以及文件夹的命令记录
- Mysql命令行导入sql数据
- mysql下修改engine引擎的方法
- 用css实现隐藏文本框
- Jquery 扩展方法
- 成大事必须依靠的五种人
- JQuery 中几个类选择器的简单使用介绍
- jQuery实现渐变下拉菜单的简单方法
- 浅析Bootstrap表格的使用
- C++ 自定义控件的移植问题
- 非常漂亮的让背景如此暗淡(一种弹出提示信息时页面背景色调改变的方法)
- 浅谈Android RecyclerView 间距全适配
- 详解Vue.js在页面加载时执行某个方法
- python实现电子书翻页小程序
- Java多线程 volatile关键字详解
