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

  • c# 切换windows桌面背景
    c# 切换windows桌面背景
    2013-07-19下载
    积分:1
  • gzobal
    学习WTL编程的例子,可以实现类似 net2003的Tab界面()
    2018-06-20 12:00:36下载
    积分:1
  • press_test
    用C++编写的系统压力测试程序,包括进程压力测试与线程压力测试。(Written in C++, system pressure testing procedures, including the process of stress testing and stress testing thread.)
    2016-05-07 19:01:34下载
    积分:1
  • search_file
    说明:  实现目录中文件查找,遍历,基本实现dir功能(Document the achievement of the directory search, traversal, the basic function of the realization of dir)
    2009-08-17 21:48:22下载
    积分:1
  • c# winform html辑器 示例源码
    快捷键 功能ctrl b 给选中字设置为加粗ctrl c 复制选中内容ctrl x 剪切选中内容ctrl v 粘贴ctrl y 重新执行上次操作ctrl z 撤销上一次操作ctrl i 给选中字设置为斜体ctrl u 给选中字加下划线ctrl a 全部选中shift enter 软回车
    2013-09-22下载
    积分:1
  • OperationSystem_RR
    操作系统 CPU调度 时间片轮转法 SSD系列课程 给有需要的同学(Operating System CPU time slice Round-Robin Scheduling SSD series of courses to students in need)
    2010-12-31 09:54:57下载
    积分:1
  • desquirr
    decompiler, ida的插件代码,可以反编译asm(Decompiler, Ida plug-in code, the compiler can be anti-asm)
    2006-06-26 14:22:06下载
    积分:1
  • ProcessInfo
    显示当前系统运行的进程,并能够查看进程中所加载的模块(show the system process and modules)
    2013-08-10 21:50:16下载
    积分:1
  • puia
    用C++实现了梯度下降求多元函数极值的算法,有可能会陷入局部最优解()
    2018-02-17 18:52:09下载
    积分: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
  • 696518资源总数
  • 106161会员总数
  • 5今日下载