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

  • getmac
    说明:  vc编写的获取windows平台网络硬件地址的软件(get windows mac address)
    2020-06-21 19:00:01下载
    积分:1
  • CCpuId100
    得到CPU信息的程序.不过好像不准.(Program which obtains CPU information, But it seems not so accuracy.)
    2002-04-19 09:18:04下载
    积分:1
  • GetHardInfo
    使用CBuild编写的一组提取计算机硬件信息的函数,包括取得CPUID,硬盘ID,Bios,网卡等(Use CBuild extract prepared a set of functions of computer hardware information, including access to CPUID, drive ID, Bios, network cards, etc.)
    2016-04-29 11:15:05下载
    积分:1
  • C#实现 CPU内存使用率 功能源码
    动态实时显示CPU 内存、当前进程数 等数据
    2013-01-18下载
    积分:1
  • C# qq自动发送消息 实例源码
    qq自动发送好友消息
    2014-08-08下载
    积分:1
  • 监听webbrowser所有请求(含 js/css/flash/ajax 等请求) 附完整源码
    IE11下不可用,请在低版本IE测试 监听webbrowser的所有请求以及查看 请求的详细,含session cookie 请求标题等信息 其中参考了如下项目:http://www.codeproject.com/Articles/38616/Retrieve-HttpOnly-Session-Cookie-in-WebBrowser
    2013-05-10下载
    积分:1
  • C#简单游戏键盘外挂
    C#简单游戏键盘外挂
    2013-10-31下载
    积分:1
  • jigh_matlhb_com
    VC具有高效率的优点,通过com接口将VC和matlab进行连接(VC has the advantages of high efficiency, through the com interface will connect VC and matlab)
    2017-07-22 04:38:08下载
    积分:1
  • 651703
    卷轴位图,通过不断计算坐标,由定时器发送消息相应,反复重新贴图!()
    2017-09-17 07:59:18下载
    积分:1
  • Snow
    调用API 桌面飘雪,圣诞雪花、、、、、、、、、、、、、、、、、、、、、、、
    2013-11-09 20:27:40下载
    积分:1
  • 696516资源总数
  • 106914会员总数
  • 0今日下载