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

  • arp
    在windows平台下的一个ARP程序,有些安装VC++软件不完整的可能不包含部分同文件,Iphlpapi.h可以下载后放进include文件夹下面即可,通过程序帮助理解协议的本身(In a windows platform ARP procedures, and some installation VC++ Incomplete software may not contain some of the same document, Iphlpapi.h can be downloaded into the folder include the following can, through the procedure to help understand the agreement itself)
    2008-04-15 09:08:34下载
    积分:1
  • asd
    WO YIJING CHUAN GUO LE A S
    2011-02-12 14:13:09下载
    积分:1
  • howtoMatlab7VC++6dll
    如何将Matlab7.0函数转换成VC++6.0动态链接库,浅显易懂(How to convert Matlab7.0 function VC++ 6.0 dynamic link library, easy to understand)
    2008-04-13 19:37:14下载
    积分:1
  • openclosetime
    读取系统日志,获取开关机时间之后做计算工时(After reading hours to do the calculation system logs for switch time)
    2014-07-15 11:00:45下载
    积分:1
  • DeviceVolumeMonitor
    trap windows message using .net framework in c#
    2009-10-19 03:25:16下载
    积分:1
  • 105
    仁脸识别是机器视觉和模式识别领域最富有挑战性的课题之一,同时也具有较为广泛的应用意义。人脸识别技术是一个非常活跃的研究领域,它覆盖了数字图像处理、模式识别、计算机视觉、神经网络、心理学、生理学、数学等诸多学科的内容(Ren-face recognition is the field of machine vision and pattern recognition, one of the most challenging issues, but also a wide range of applications has more significance. Face recognition technology is a very active research field, which covers the digital image processing, pattern recognition, computer vision, neural networks, psychology, physiology, mathematics and many other disciplines content)
    2008-12-11 16:17:33下载
    积分:1
  • program-of-automatic-shut-dowm
    可以定时关机,重启计算机,对编写一些程序时添加人性化功能有很大帮助。(Can be timed shutdown, restart the computer)
    2016-05-07 19:30:53下载
    积分:1
  • c# 日志组件完整源码下载
    c# 日志组件完整源码下载
    2021-04-13 02:58:56下载
    积分:1
  • Pass
    关于TP对KdDisableDebugger双机限制的解决代码。(TP limit of KdDisableDebugger double machine to solve the code.)
    2013-04-02 10:28:37下载
    积分:1
  • wendang
    让系统查找某一程序进程被关闭则运行关机命令(The system to find a program process is shut down while running shutdown command)
    2016-05-08 11:01:59下载
    积分:1
  • 696524资源总数
  • 103930会员总数
  • 47今日下载