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#实现多线程写入同一个文件的方法
本文实例讲述了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#实现强制关闭当前程序进程
/// <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.Diagnostics; namespace ConsoleApp { class ProcessDo { /// <summary> /// 获取进程相关信息 /// </summary> pub
-
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#启动进程的几种常用方法.分享给大家供大家参考.具体如下: 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#线程池操作方法.分享给大家供大家参考.具体如下: 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#中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.IO; using System.Threading; using System.Net; namespace WfpApp { public class MultiDownload { #region 变量 pri
-
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 { //用于顯示狀態的代理
随机推荐
- linux使用update-alternatives切换java版本
- Ruby中的迭代器详解
- javascript使用eval或者new Function进行语法检查
- ExtJS Window 最小化的一种方法
- Vue数据驱动模拟实现4
- 详解vue-router 2.0 常用基础知识点之router-link
- 如何在Angular2中使用jQuery及其插件的方法
- 详解SpringBoot中Session超时原理说明
- PL/SQL number型数据
- javascript实现图片左右滚动效果【可自动滚动,有左右按钮】
- 微信小程序中子页面向父页面传值实例详解
- asp.net 数字签名实例代码
- C#开源的AOP框架--KingAOP基础
- Android 软键盘状态并隐藏输入法的实例
- 完美解决PJ的Cookies保存时限问题!可选择记录登陆时长!
- 命令行第1/2页
- rsync只同步指定目录的方法(已测)
- 时间处理函数工具分享(时间戳计算)
- android 横竖屏限制的配置方法
- Ajax 加载数据 练习代码
