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#队列Queue多线程用法实例
本文实例讲述了C#队列Queue多线程用法.分享给大家供大家参考.具体分析如下: 这里展示一个例子,供学习使用: private void button_测试Queue结合多线程_Click(object sender, EventArgs e) { Console.WriteLine("初始化队列"); queue = new Queue<string>(); string[] cars = new string[]{"宝马","奔驰&quo
-
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#实现多线程下载文件的方法.分享给大家供大家参考.具体实现方法如下: 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#线程池操作方法
本文实例讲述了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#停止线程的方法
本文实例讲述了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#实现多线程写入同一个文件的方法
本文实例讲述了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.Diagnostics; namespace ConsoleApp { class ProcessDo { /// <summary> /// 获取进程相关信息 /// </summary> pub
-
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#中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.Threading; using System.Collections; using System.Windows.Forms; namespace ThredProcessQueue { //用于顯示狀態的代理
随机推荐
- 如何把一长串数字分位显示?
- SQLServer与Access常用SQL函数区别
- 改进版通过Json对象实现深复制的方法
- Javascript使用正则验证身份证号(简单)
- 使用java生成字母验证码
- iOS中将个别页面强制横屏其他页面竖屏
- perl 删除数组元素的几种方法小结
- js实现select组件的选择输入过滤代码
- Windows下IIS6/Apache2.2.4+MySQL5.2+PHP5.2.1安装配置方法
- nginx 如何实现读写限流的方法
- 纯C语言:贪心Prim算法生成树问题源码分享
- 使用正则表达式匹配tsql注释语句
- jQuery AjaxQueue改进步骤
- 在dos(CMD)下建立VPN的方法
- 详解spring Boot 集成 Thymeleaf模板引擎实例
- C#代码设置开机启动示例
- 基于C程序启动代码的深入分析
- vue项目实战总结篇
- vue过滤器用法实例分析
- Python3模拟curl发送post请求操作示例