资源简介
winform多线程与窗体数据交互 C# winform thread
代码片段和文件信息
using System;
using System.Threading;
using System.ComponentModel;
namespace WindowsFormsApplication1
{
public interface IAsyncEventArgs
{
int action { get; }
object[] getobjects { get; }
}
///
/// 线程事件参数
///
internal class AsyncEventArgs : EventArgs IAsyncEventArgs
{
private readonly int m_action;
private readonly object[] m_objects;
public int action
{
get { return this.m_action; }
}
public object[] getobjects
{
get { return this.m_objects; }
}
public AsyncEventArgs(int action object[] objs)
{
this.m_action = action;
this.m_objects = objs;
}
}
///
/// 异步操作基类基类不需要修改,任务应该在子类中完成
/// 注意:只适用用winform开发
///
public abstract class Asyncbase
{
private Thread m_thread;
private readonly ISynchronizeInvoke m_Target;
private bool m_IsStop = false;
private bool[] m_isCancelFlag = new bool[]{falsefalse};
protected int m_action = 0;
public event EventHandler TaskBefore;
public event EventHandler TaskProgress;
public event EventHandler TaskDone;
public event EventHandler Complete;
public event EventHandler Error;
//开始执行任务之前
private void OnTaskBefore(object sender)
{
toTarget(TaskBefore new object[] { sender new AsyncEventArgs(this.m_action null) });
}
//执行任务进度
protected void OnTaskProgress(object sender int step)
{
toTarget(TaskProgress new object[] { sender new AsyncEventArgs(this.m_action new object[] { step }) });
}
//执行任务成功完成(只有任务成功才会执行,取消和异常均不会执行),传递给主线程的对象在这里设置
protected void OnTaskDone(object sender object[] objs)
{
toTarget(TaskDone new object[] { sender new AsyncEventArgs(this.m_action objs) });
}
//执行任务时发生异常
private void onerror(object sender Exception exp)
{
toTarget(Error new object[] { sender new AsyncEventArgs(this.m_action new object[] { exp }) });
}
//完成一个任务,无论如果都会执行
private void OnComplete(object sender)
{
toTarget(Complete new object[] { sender new AsyncEventArgs(this.m_action null) });
}
///
/// 构造方法
///
/// 调用目标
protected Asyncbase(ISynchronizeInvoke target)
{
this.m_Target = target;
this.m_thread = null;
}
~Asyncbase()
{
Stop();
}
//启动一个工作线程
public void Start()
{
try
{
this.m_thread = new Thread(new ThreadStart(Work));
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2012-12-20 13:48 WindowsFormsApplication1\
目录 0 2012-12-20 13:48 WindowsFormsApplication1\WindowsFormsApplication1\
文件 914 2012-12-20 10:45 WindowsFormsApplication1\WindowsFormsApplication1.sln
文件 24064 2012-12-20 13:47 WindowsFormsApplication1\WindowsFormsApplication1.suo
文件 6962 2012-12-20 13:37 WindowsFormsApplication1\WindowsFormsApplication1\Async.cs
文件 2383 2012-12-20 13:45 WindowsFormsApplication1\WindowsFormsApplication1\AsyncImport.cs
目录 0 2012-12-20 13:48 WindowsFormsApplication1\WindowsFormsApplication1\bin\
目录 0 2012-12-20 13:48 WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\
文件 14848 2012-12-20 13:46 WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe
文件 38400 2012-12-20 13:46 WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb
文件 11608 2012-12-20 13:46 WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe
文件 490 2010-03-17 22:39 WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest
文件 6008 2012-12-20 13:46 WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs
文件 4788 2012-12-20 13:45 WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs
文件 5817 2012-12-20 11:24 WindowsFormsApplication1\WindowsFormsApplication1\Form1.resx
目录 0 2012-12-20 13:48 WindowsFormsApplication1\WindowsFormsApplication1\obj\
目录 0 2012-12-20 13:48 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\
目录 0 2012-12-20 13:48 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\
文件 6256 2012-12-20 13:46 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 686 2012-12-20 13:46 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\GenerateResource-ResGen.read.1.tlog
文件 1222 2012-12-20 13:46 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\GenerateResource-ResGen.write.1.tlog
目录 0 2012-12-20 10:45 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\TempPE\
文件 1443 2012-12-20 13:46 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt
文件 14848 2012-12-20 13:46 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.exe
文件 180 2012-12-20 13:46 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Form1.resources
文件 38400 2012-12-20 13:46 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.pdb
文件 180 2012-12-20 13:46 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Properties.Resources.resources
文件 505 2012-12-20 10:45 WindowsFormsApplication1\WindowsFormsApplication1\Program.cs
目录 0 2012-12-20 13:48 WindowsFormsApplication1\WindowsFormsApplication1\Properties\
文件 1380 2012-12-20 10:45 WindowsFormsApplication1\WindowsFormsApplication1\Properties\AssemblyInfo.cs
文件 2896 2012-12-20 10:45 WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.Designer.cs
............此处省略5个文件信息
相关资源
- 佳博条码打印机C#
- wpf界面切换特效
- C#多线程编程实战Code源代码
- C# winfrom批量添加文字。图片水印
- c# TTS语音 附带 DotNetSpeech.dll语音类库
- 一个用c#文件流写的通讯录
- C# 将图片文件转换成字节流存储在T
- 实现自定义的Web服务器(C#)
- 微信公众平台 网页授权获取用户基本
- C#做一个悬浮窗口程序
- C# 命名管道 异步通信的
- C#数组的随机排序源码
- 基于C#窗体的五子棋游戏简单Demo
- 基于c#的串口通信获取温湿度传感器数
- C#&Csgl进行OpenGL编程
- 自动识别插入电脑设备的代码c#USB串口
- C# 对Cookie、Session、Cache的操作辅助类
- A*寻路算法实现C#源码——A Star find
- 用C#实现文本朗读和语音识别功能
- C#写入与读取Cookie C#.Net代码
- C#的一个B/S
- C#如何动态添加或删除窗体中的控件(
- c#影院售票系统(含数据库)
- head first c# lab3(入侵者游戏)
- C# IC卡读写源码(纯代码,无封装)
- C# 小票打印源码
- C#开发实战1200例第2卷源码
- C#开发实战1200例第1卷源码
- Voronoi Diagram维诺图
- .NET/C# 英文面试题[附答案]汇总 1
评论
共有 条评论