Concurrency in csharp (Asynchronous, Parallel, and Multithreaded Programming)
http://stephencleary.com/projects/
/// <summary>
///
/// </summary>
public partial class Form2 : Form
{ //[ComVisible(false)]
//public delegate void ParameterizedThreadStart(object objfield); /// <summary>
///
/// </summary>
public Form2()
{
InitializeComponent();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form2_Load(object sender, EventArgs e)
{
MyDu du = new MyDu(); Control.CheckForIllegalCrossThreadCalls = false;
Thread t1 = new Thread(new ThreadStart(TestMethod));
Thread t2 = new Thread(new ParameterizedThreadStart(TestMethod));
//Thread t3 = new Thread(new ThreadStart(du.setData));
ThreadPool.QueueUserWorkItem(new WaitCallback(TaskProc1), new Person { Id = 1, Name = "测试", Count =100 }); du.BegID = 100;
du.EndID = 20000;
du.Le1 = this.label3;
du.Le2 = this.label4;
Thread t3 = new Thread(new ThreadStart(du.Run)); t1.IsBackground = true;
t2.IsBackground = true;
t3.IsBackground = true;
t1.Start();
t2.Start("hello");
t3.Start();
}
/// <summary>
///
/// </summary>
/// <param name="x"></param>
public void TaskProc1(object x) //执行的任务
{
Person person = x as Person; }
//
private delegate void InvokeCallback(string msg);
//
private delegate void SetLabelDelegate(string value);
/// <summary>
///
/// </summary>
void TestMethod()
{ //InvokeCallbackmsgCallback = new InvokeCallback(m_comm_MessageEvent);
string v = "geovind du 1";
this.label1.Text = v;
//if (this.InvokeRequired)
//{
// SetLabelDelegate d = new SetLabelDelegate(TestMethod);
// this.Invoke(d, new object[] { v});
//}
//else
//{
// this.label1.Text = v;
//}
} void TestMethod(object data)
{
if (this.InvokeRequired)
{
SetLabelDelegate d = new SetLabelDelegate(TestMethod);
this.Invoke(d, new object[] { data });
}
else
{
string datastr = data as string;
this.label2.Text = datastr;
}
} } public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public int Count { get; set; } }
/// <summary>
///
/// </summary>
class MyDu
{ private int begID; public int BegID { set{this.begID=value;} } private int endID; public int EndID { set{this.endID=value;} } private Label le1; public Label Le1
{
set { this.le1 = value; }
} private Label le2; public Label Le2
{
set { this.le2 = value; }
}
/// <summary>
///
/// </summary>
public void Run()
{ method(begID, endID, le1, le2); }
/// <summary>
///
/// </summary>
/// <param name="begin"></param>
/// <param name="end"></param>
private void method(int begin,int end,Label labe,Label labe2)
{
labe.Text = begin.ToString();
labe2.Text = end.ToString();
} }
}
Concurrency in csharp (Asynchronous, Parallel, and Multithreaded Programming)的更多相关文章
- What is the difference between concurrency, parallelism and asynchronous methods?
Ref: http://stackoverflow.com/questions/4844637/what-is-the-difference-between-concurrency-paralleli ...
- (转) [it-ebooks]电子书列表
[it-ebooks]电子书列表 [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Obj ...
- Introduction to Multi-Threaded, Multi-Core and Parallel Programming concepts
https://katyscode.wordpress.com/2013/05/17/introduction-to-multi-threaded-multi-core-and-parallel-pr ...
- PatentTips - Heterogeneous Parallel Primitives Programming Model
BACKGROUND 1. Field of the Invention The present invention relates generally to a programming model ...
- A Pattern Language for Parallel Application Programming
A Pattern Language for Parallel Application Programming Berna L. Massingill, Timothy G. Mattson, Bev ...
- Java 8 Concurrency Tutorial--转
Threads and Executors Welcome to the first part of my Java 8 Concurrency tutorial. This guide teache ...
- 【转】Multithreaded Python Tutorial with the “Threadworms” Demo
The code for this tutorial can be downloaded here: threadworms.py or from GitHub. This code works wi ...
- Introduction to Parallel Computing
Copied From:https://computing.llnl.gov/tutorials/parallel_comp/ Author: Blaise Barney, Lawrence Live ...
- 并行parallel和并发concurrent的区别
http://stackoverflow.com/questions/1050222/concurrency-vs-parallelism-what-is-the-difference Concurr ...
随机推荐
- 《CLR.via.C#第三版》第二部分第13章节 接口 读书笔记(七)
这章的书写感觉很普通,是些基础的认知知识. 其中一点的重要认知,泛型接口的好处(其实也是使用泛型的好处之一):编译时类型安全&处理值类型时减少装箱. 再说点书上没有的.本来这些知识我打算另外分 ...
- 扫描仪API接入大全:Twain, WIA 或 两者不具有.[换个思路 春暖花开]
最近做和扫描仪接入的扫描应用程序,深深感觉到了来自底层设备和WINDOWS协议的恶意.软件专业,对计算机深层次通知机制和协议,以及与之相连接的机器的接入协议和一些参数,当时并木有认真学习和了解,前一阵 ...
- .Net程序员面试所需要的一些技术准备
夜已经很深了,但却毫无睡意,最近找工作和面试感触良多,所以想记录下来这段过程. 作为一个.Net程序员,不可否认是比JAVA要难混的.甚至在智联招聘或者大街网都没有.NET程序员的备用选项.真是令人悲 ...
- VBA批量查找和复制文件
Function findAndCopy(srcFile As String, destFile As String, cmdFile As String) Dim WSH As Object, wE ...
- AMD规范与CMD规范的区别
AMD规范与CMD规范的区别是什么? 在比较之前,我们得先来了解下什么是AMD规范?什么是CMD规范?当然先申明一下,我个人也是总结下而已,也是网上看到的资料,自己总结下或者可以说整理下而已,供 ...
- 虚拟机网络驱动(共享文件夹)不见了的解决方案-适用于win7~win10 and Windows Server 2008~Windows Server 2012R2
具体看图 手动打入下面选择部分的字符 \\vmware-host\Shared Folders 然后就可以了,这边有个红叉,重启后就没了 重启后
- SQL Server 2014新特性探秘(2)-SSD Buffer Pool Extension
简介 SQL Server 2014中另一个非常好的功能是,可以将SSD虚拟成内存的一部分,来供SQL Server数据页缓冲区使用.通过使用SSD来扩展Buffer-Pool,可以使得大量随 ...
- 传智播客--ADO.net--SqlBulkCopy批量插入数据(小白必知)
一般情况下,我们在向数据库中插入数据时用Insert语句,但是当数据量很大的时候,这种情况就比较缓慢了,这个时候就需要SqlBulkCopy这个类. SqlBulkCopy本身常用的函数有这么几个 D ...
- Android okHttp网络请求之缓存控制Cache-Control
前言: 前面的学习基本上已经可以完成开发需求了,但是在项目中有时会遇到对请求做个缓存,当没网络的时候优先加载本地缓存,基于这个需求我们来学习一直okHttp的Cache-Control. okHttp ...
- 通过setTimeout来取消因大量计算造成的网页卡顿
js是单线程的,所以有些大量计算的操作会占用线程资源,导致页面卡住. 今天遇到这样一个场景,选择一个下拉框之后,对数据进行筛选,这个过程中有大量计算,点了selecte的option之后,option ...