=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 136
下载积分: 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 个回复

  • 34378387
    一个模拟骰子的小系统, 虽然简单,但是覆盖知识面很全的喔(A small system simulation of the dice, although simple, but full of knowledge is very well)
    2017-08-21 11:51:41下载
    积分:1
  • 修改寄存器
    说明:  修改系统寄存器 在UEFI的环境下,,,,,,(Modify System Register)
    2020-06-22 05:20:02下载
    积分:1
  • deny_cmd
    Deny running of specify process
    2010-11-12 01:53:36下载
    积分:1
  • 数据库导入和筛选工具
    数据库导入和筛选工具
    2017-03-17下载
    积分:1
  • wk_dz
    Visual C++案例开发集锦第六章\获取网卡地址的程序源码,值得一看!(Visual C++ case development highlights Chapter to obtain the Ethernet address of the program source code, worth a visit!)
    2011-08-13 16:07:33下载
    积分:1
  • Src1
    这是一个SDK程序。本程序跟踪显示鼠标的坐标位置,同时,若有鼠标操作,可在窗口标题栏中显示操作信息,要是在窗口客户区中进行双击,就会在双击位置点上显示位置信息。 (This is an SDK program. This procedure tracking shows the coordinates of the mouse position, and if the mouse can be displayed in the window s title bar operating information, if the customer area of the window to double-click, double-click the location of points will be shown on location information.)
    2004-06-08 19:27:00下载
    积分:1
  • jcaj
    vc 检测键盘按键 的程序源码,感兴趣的可以看看(vc test program source code of keyboard keys, can be of interest to see)
    2011-09-08 22:09:43下载
    积分:1
  • Go-ICP_V1.3
    Go ICP for the registration of point couds
    2017-03-06 23:42:41下载
    积分:1
  • Font_Previewer
    一个不错的系统字体预览工具附源码。很实用的系统字体预览工具,附有全部源码,可以很直观的看到系统各种字体的模样,便于你管理系统字体。(A good system font preview tool attached source code. A very practical system font preview tool, with full source code, the system can be very intuitive to see the appearance of a variety of fonts, easy to manage your system fonts.)
    2009-09-10 12:36:19下载
    积分:1
  • WinIO
    说明:  并口库函数,对于并口控制时必须用到的库。(Parallel library function, the parallel port control library must be used.)
    2008-11-02 01:00:34下载
    积分:1
  • 696518资源总数
  • 104349会员总数
  • 32今日下载