=amount){Console.WriteLine("原有余额:"balance);Console.WriteLine("支取余额:-"amount);balance=balance-amount;Console.WriteLine("现有余额:"balance);returnamount;}else{return0;//拒绝交易}}}//测试交易publicvoidDoTransactions(){//支取随机的金额100次for(inti=0;i<100;i){Withdraw(r.Next(1,100));}}}//**********************************************************************************privatevoidbutton1_Click(objectsender,EventArgse){Packagepack=newPackage();//创建包含线程方法的对象SendPackageserver=newSendPackage(pack,20);ReceivePackageclient=newReceivePackage(pack,20);//创建两个线程对象,一个用于发送数据包,另一个用于接收数据包Threadproducer=newThread(newThreadStart(server.ThreadRun));Threadconsumer=newThread(newThreadStart(client.ThreadRun));try{//启动两个线程producer.Start();consumer.Start();//等待两个线程结束producer.Join();consumer.Join();}catch(ThreadStateExceptionex){Console.WriteLine(e);}catch(ThreadInterruptedExceptionex){Console.WriteLine(e);}}privatevoidbutton2_Click(objectsender,EventArgse){//建立10个线程同时进行交易Thread[]threads=newThread[10];Accountacc=newAccount(1000);for(inti=0;i<10;i){threads[i]=newThread(newThreadStart(acc.DoTransactions));}for(inti=0;i<10;i){threads[i].Start();}}}}-IMDN开发者社群-imdn.cn"> =amount){Console.WriteLine("原有余额:"balance);Console.WriteLine("支取余额:-"amount);balance=balance-amount;Console.WriteLine("现有余额:"balance);returnamount;}else{return0;//拒绝交易}}}//测试交易publicvoidDoTransactions(){//支取随机的金额100次for(inti=0;i<100;i){Withdraw(r.Next(1,100));}}}//**********************************************************************************privatevoidbutton1_Click(objectsender,EventArgse){Packagepack=newPackage();//创建包含线程方法的对象SendPackageserver=newSendPackage(pack,20);ReceivePackageclient=newReceivePackage(pack,20);//创建两个线程对象,一个用于发送数据包,另一个用于接收数据包Threadproducer=newThread(newThreadStart(server.ThreadRun));Threadconsumer=newThread(newThreadStart(client.ThreadRun));try{//启动两个线程producer.Start();consumer.Start();//等待两个线程结束producer.Join();consumer.Join();}catch(ThreadStateExceptionex){Console.WriteLine(e);}catch(ThreadInterruptedExceptionex){Console.WriteLine(e);}}privatevoidbutton2_Click(objectsender,EventArgse){//建立10个线程同时进行交易Thread[]threads=newThread[10];Accountacc=newAccount(1000);for(inti=0;i<10;i){threads[i]=newThread(newThreadStart(acc.DoTransactions));}for(inti=0;i<10;i){threads[i].Start();}}}} - IMDN开发者社群-imdn.cn">
登录
首页 » C# » c# 多线程操作例子源码

c# 多线程操作例子源码

于 2015-03-20 发布
0 181
下载积分: 1 下载次数: 0

代码说明:

多线程操作 [实例截图] [核心代码]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;using System.Threading;namespace ThreadMore{ public partial class Form3 : Form { public Form3() { InitializeComponent(); } // 发送数据包的类 public class SendPackage { Package pack; // 保存将被发送的数据包 int quantity = 1; // 数据包的个数 // 发送数据包 public SendPackage(Package p, int count) { pack = p; quantity = count; } public void ThreadRun() { // 发送指定数量的数据包 for (int looper = 1; looper

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • HookFindNextFile
    hook findnextfile 隐藏文件(hook findnextfile hidden files)
    2009-10-10 23:22:12下载
    积分:1
  • hsad
    说明:  利用DevC++写的Windows基本控件的类库,有详细的使用例子,水平有限,希望指正(Use DevC to write the Windows basic control class library, have detailed use example, the level is limited, want to point to correct)
    2018-12-30 20:31:07下载
    积分:1
  • pigdjas67
    说明:  By throwing an exception to indicate the occurrence of an error(By throwing an exception to indicate the occurrence of an erro)
    2018-12-25 13:29:14下载
    积分:1
  • rgebks
    这是个可以实现UTF-8与GB2312之间的互换类,不错(This is a can realize utf-8 and GB2312 swaps between classes, is good)
    2017-04-03 15:17:15下载
    积分:1
  • JieMiJi
    产生程序序列号JieMiJi,很不错的vc源码,希望能对大家有所帮助(Generation process serial number JieMiJi, very good vc source, I hope you can help)
    2011-09-07 22:45:04下载
    积分:1
  • MFC利用ChartCtrl快速实现波形显示实例源码
    MFC利用ChartCtrl快速实现波形显示实例源码
    2020-12-10下载
    积分:1
  • intel8xC196
    intel 的很早的CPU芯片资料了,不过对学习CPU的结构和了解CPU发展还是有帮助的(intel the early information available to the CPU chip, but the CPU for learning and understanding the structure of CPU development or help)
    2008-12-30 14:48:31下载
    积分:1
  • C#工业控制——机械手项目实例
    【实例简介】连接机器人并进行相关操作
    2021-07-29 00:31:15下载
    积分:1
  • Regedit
    vc 编辑注册表信息Regedit的程序源码,值得一看!(vc edit the registry Regedit program source code, worth a visit!)
    2011-07-01 22:03:37下载
    积分:1
  • Notepad++ 源码下载
    notepad-plus-plus-master.zip
    2019-12-09下载
    积分:1
  • 696518资源总数
  • 105547会员总数
  • 4今日下载