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

  • 读取WebBrowser中的Cookies(含Session)信息 并赋值给HttpWebRequest 执行模拟网页操作
    通常大家通过 webbrowser.document.cookies 只能得到cookie但是得不到 session,这个实例也得到了session
    2013-01-05下载
    积分:1
  • DumpEC
    使用WinIO访问笔记本EC的所有寄存器和存储空间。本程序适用ENE EC KB3926(EC laptop using WinIO access to all registers and storage space. This procedure applies to ENE EC KB3926)
    2021-01-14 20:58:47下载
    积分:1
  • SendMessage模拟鼠标单击事件(在webbrowser网页实现) 实例完整源码
    一个利用winapi模拟鼠标单击webbrowser中网页实例
    2013-04-04下载
    积分:1
  • LOF
    列举制定的目录中被打开的文件,和打开这些文件的进程的PID,命令:lof 驱动文件 目标文件夹。由于驱动的限制,该程序仅适用Windows 2000/XP。(Listed in the directory has been developed to open the file, and open the files of the process PID, the command: lof driver file destination folder. As the driving restrictions, the program applies only to Windows 2000/XP.)
    2010-03-13 22:36:30下载
    积分:1
  • C# 仿任务管理器源码下载 实现了 cpu/内存/进/硬盘等实时数据
    C# 仿任务管理器源码下载 实现了 cpu/内存/进程/硬盘等实时数据
    2014-01-21下载
    积分:1
  • press_test
    用C++编写的系统压力测试程序,包括进程压力测试与线程压力测试。(Written in C++, system pressure testing procedures, including the process of stress testing and stress testing thread.)
    2016-05-07 19:01:34下载
    积分:1
  • gettime
    一个记录开关机时间的软件,可以实现开机自运行(a record time for the switch software can be run in Flint)
    2005-04-14 17:48:56下载
    积分:1
  • opaxuemfapshot
    如何在Windows 9598下读取硬盘序列号,硬盘的序列号是生产时由厂家设定()
    2017-11-11 22:39:51下载
    积分:1
  • 62228498
    一个国产RPG游戏 详细讲解RPG游戏的开发过程,还有源码()
    2018-06-13 03:55:41下载
    积分:1
  • WCRT-1.12
    windows 运行时库 crt 的源代码(windows runtime crt source code)
    2012-04-20 13:27:40下载
    积分:1
  • 696516资源总数
  • 106457会员总数
  • 15今日下载