資源簡(jiǎn)介
winform多線程與窗體數(shù)據(jù)交互 C# winform thread

代碼片段和文件信息
using?System;
using?System.Threading;
using?System.ComponentModel;
namespace?WindowsFormsApplication1
{
????public?interface?IAsyncEventArgs
????{
????????int?action?{?get;?}
????????object[]?getobjects?{?get;?}
????}
????///?
????///?線程事件參數(shù)
????///?
????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;
????????}
????}
????///?
????///?異步操作基類基類不需要修改,任務(wù)應(yīng)該在子類中完成
????///?注意:只適用用winform開發(fā)
????///?
????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;
????????//開始執(zhí)行任務(wù)之前
????????private?void?OnTaskBefore(object?sender)
????????{
????????????toTarget(TaskBefore?new?object[]?{?sender?new?AsyncEventArgs(this.m_action?null)?});
????????}
????????//執(zhí)行任務(wù)進(jìn)度
????????protected?void?OnTaskProgress(object?sender?int?step)
????????{
????????????toTarget(TaskProgress?new?object[]?{?sender?new?AsyncEventArgs(this.m_action?new?object[]?{?step?})?});
????????}
????????//執(zhí)行任務(wù)成功完成(只有任務(wù)成功才會(huì)執(zhí)行,取消和異常均不會(huì)執(zhí)行),傳遞給主線程的對(duì)象在這里設(shè)置
????????protected?void?OnTaskDone(object?sender?object[]?objs)
????????{
????????????toTarget(TaskDone?new?object[]?{?sender?new?AsyncEventArgs(this.m_action?objs)?});
????????}
????????//執(zhí)行任務(wù)時(shí)發(fā)生異常
????????private?void?onerror(object?sender?Exception?exp)
????????{
????????????toTarget(Error?new?object[]?{?sender?new?AsyncEventArgs(this.m_action?new?object[]?{?exp?})?});
????????}
????????//完成一個(gè)任務(wù),無論如果都會(huì)執(zhí)行
????????private?void?OnComplete(object?sender)
????????{
????????????toTarget(Complete?new?object[]?{?sender?new?AsyncEventArgs(this.m_action?null)?});
????????}
????????///?
????????///?構(gòu)造方法
????????///?
????????///?調(diào)用目標(biāo)
????????protected?Asyncbase(ISynchronizeInvoke?target)
????????{
????????????this.m_Target?=?target;
????????????this.m_thread?=?null;
????????}
????????~Asyncbase()
????????{
????????????Stop();
????????}
????????//啟動(dòng)一個(gè)工作線程
????????public?void?Start()
????????{
????????????try
????????????{
????????????????this.m_thread?=?new?Thread(new?ThreadStart(Work));
?
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????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個(gè)文件信息
- 上一篇:wpf界面切換特效
- 下一篇:佳博條碼打印機(jī)C#
評(píng)論
共有 條評(píng)論