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

  • gc
    说明:  简单垃圾回收器本人以多次试用效果不错,请大家多提意见 (Simple garbage collector I would like to try the effect of a good many times, please do so everyone)
    2007-08-07 10:54:52下载
    积分:1
  • direce3D
    语音3D特效器制作, 获取3D缓冲区对象,最大距离和最小距离等具体设置(3D audio effects device production, access to 3D buffer object, the maximum distance and minimum distance from a specific set)
    2009-11-06 16:29:55下载
    积分:1
  • DrvSpace
    获取磁盘空间数据DrvSpace,很不错的vc源码,希望能对大家有所帮助(Disk space for data DrvSpace, very good vc source code, I hope you can help)
    2011-09-06 22:59:51下载
    积分:1
  • Go-ICP_V1.3
    Go ICP for the registration of point couds
    2017-03-06 23:42:41下载
    积分:1
  • entry_dos
    便捷的dos进入工具,非常方便开发人员使用,提高工作效率(Dos and convenient access to tools to developers is very convenient to use, improve efficiency)
    2011-05-18 17:06:13下载
    积分:1
  • SoftScope
    功能描述:这是一个示波器波形显示控件,能够完成类似于示波器的功能。最多可以同时显示8个通道的数据波形,可以动态切换显示通道。缩放xy轴,弹出半透明窗口显示坐标,y轴方向平移波形等功能。 操作使用键盘快捷键,操作说明见readme.txt,目前按键焦点的得到有点问题,要点击开始后在示波器上鼠标左键单击一下,然后按一下上箭头键,才可以响应按键指令,有高手知道怎么改进希望告诉作者:xiang57@163.com(Functional Description: This is an oscilloscope waveform display control, able to complete similar oscilloscope function. At the same time show up to eight channels of waveform data can be displayed dynamically switch channels. Zoom xy axis, translucent pop-up window displays the coordinates, y-axis direction of translational wave functions. Operation of the use of keyboard shortcuts, operating instructions see readme.txt, the current key focus has been a problem, it is necessary to click on the oscilloscope after the beginning click the left mouse button, and then click on the arrow keys, before they can respond to key commands, has a master know how to tell the authors hope to improve: xiang57@163.com)
    2008-07-06 21:24:24下载
    积分:1
  • Evergreen(常青树)
    说明:  gold usd aud gbp eru aud chf
    2020-05-16 05:07:26下载
    积分:1
  • HookRegister
    控制注册表,注册表监控操作、拦截操作,结构清晰(Control registry, registry monitoring operation, blocking action)
    2011-02-01 12:00:41下载
    积分:1
  • RstAndClsCmptr
    用visual c++实现系统开关机,注销(With visual c++ to achieve switching machines, log off)
    2010-05-20 16:12:47下载
    积分:1
  • secondwatch2
    毫秒计时程序(millisecond time procedure)
    2005-01-15 21:00:37下载
    积分:1
  • 696516资源总数
  • 106914会员总数
  • 0今日下载