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

  • speech
    说明:  语音识别系统,是在vc平台编写的,仅供参考(Speech recognition system, for reference only)
    2009-08-19 19:27:39下载
    积分:1
  • REGCTRL
    说明:  注册表操作,打开注册表,查询,并进行设置。后面有注释部分是进行系统的一些信息进行设置查询。(Registry operation, open the registry, query, and set up. Notes partly behind some of the information system set up inquiries.)
    2008-11-07 18:11:18下载
    积分:1
  • BMPopenandsave
    该程序为BMP图像处理,能够打开和存储任何一幅图像格式为BMP,特别适合初学者,仅供参考!(The program for BMP image processing, to open and store any image format for BMP, especially suitable for beginners, for reference purposes only!)
    2017-05-14 10:20:10下载
    积分:1
  • MFC
    MFC Graphics Tablet Test Application
    2017-06-01 19:05:58下载
    积分:1
  • TimeTransform
    vc 时间戳转换北京时间格式(字符串) 北京时间格式转换时间戳
    2015-12-29 10:52:56下载
    积分:1
  • C#实现WindowsAPI改变 鼠标指向的任意窗体中控件的大小和位置实例
    用.net实现 改变其它任意窗体控件的属性值
    2013-01-08下载
    积分:1
  • C# 制作 IE插件例子源码下载
    IE插件实现了 统计网页浏览时间
    2014-09-11下载
    积分:1
  • HookRegister
    控制注册表,注册表监控操作、拦截操作,结构清晰(Control registry, registry monitoring operation, blocking action)
    2011-02-01 12:00:41下载
    积分:1
  • c# 监测进cpu 占用率 过高则结束进源码下载
    c# 监测进程cpu 占用率 过高则结束进程源码下载
    2014-01-22下载
    积分:1
  • Windows
    说明:  利用打印驱动程序生成SVG文件,很好的源代码下载把(Use printer driver to generate SVG documents, a very good source code to download the)
    2008-10-07 12:26:44下载
    积分:1
  • 696516资源总数
  • 106914会员总数
  • 0今日下载