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

  • 7308961
    ansi字符串与Unicode字符串转换的代码 包括UTP-8(ANSI string with Unicode string conversion code Including UTP - 8 -)
    2017-07-15 01:29:32下载
    积分:1
  • TestVirtual
    查看面向对象多态执行流程,如果父类函数为纯虚函数,则会执行子类函数.(look at multy status in executing,if farther s function no execute health, execute child s function)
    2011-01-31 09:48:25下载
    积分:1
  • CPaintDCDemo
    第6章 设备描述表和图形对象CPaintDCDemoCPaintDCDemo.rar,很不错的vc源码,有兴趣的朋友可以看看。(Chapter 6 describes the tables and graphics device object CPaintDCDemo CPaintDCDemo.rar, very good vc source, interested friends can see.)
    2011-09-11 23:02:40下载
    积分:1
  • Mouse
    该程序能够改变鼠标形状,是一个非常好的例子.(The program can change the mouse shape is a very good example.)
    2009-12-02 18:49:35下载
    积分:1
  • tslog
    历史上最强大的windows日志系统,性能是log4c的3倍 (History' s most powerful windows log system performance is log4c of 3 times)
    2010-06-21 00:59:05下载
    积分:1
  • RationalQuantifyUsage
    绝对原创,请站长加分啊,这是用来快速定位性能底下的一段测试代码,配合Quantify使用,上面附有说明,如何定位到。(Rational Quantify Usage)
    2014-06-06 10:48:34下载
    积分:1
  • C#生成二维码、调用摄像头扫描二维码实例源码
    C#生成二维码、调用摄像头扫描二维码,可直接拿来测试
    2013-01-10下载
    积分:1
  • adsl拨号 换IP 类库 以及调用示例 DotRas 源码下载
    adsl自动拨号 重拨 换ip 功能
    2013-08-08下载
    积分:1
  • 716777
    User Defined Surface Project file sample,光学设计软件zemax的用户自定义表面的例子(Examples of user-defined surfaces in User Defined Surface Project file sample, optical design software zemax)
    2018-09-29 03:15:18下载
    积分:1
  • DeviceVolumeMonitor
    trap windows message using .net framework in c#
    2009-10-19 03:25:16下载
    积分:1
  • 696518资源总数
  • 106245会员总数
  • 18今日下载