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 ...
随机推荐
- 最流行的编程语言 JavaScript 能做什么?
此文转载oschina文章 首先很遗憾的一点是,“PHP虽然是最好的语言”,但是它不是最流行的语言. 同时对不起的还有刚刚在4月TIOBE编程语言排行榜上上榜的各个语言: 你们都很棒,但是你们都担当不 ...
- “安装项目” Step By Step
目录 一 基本操作 二 定制安装对话框 三 安装程序类 四 总结 .NET程序集因为包含了元数据,所以程序集具有自描述性.多数程序自身包含了运行所需要的全部信息,这类程序集就是我们常说的“绿色软件”. ...
- CSharpGL(6)在OpenGL中绘制UI元素
CSharpGL(6)在OpenGL中绘制UI元素 2016-08-13 由于CSharpGL一直在更新,现在这个教程已经不适用最新的代码了.CSharpGL源码中包含10多个独立的Demo,更适合入 ...
- Node.js开发者最常范的10个错误
目录 前言 1 不使用开发工具 1.1 自动重启工具 1.2 浏览器自动刷新工具 2 阻塞event loop 3 频繁调用回调函数 4 圣诞树结构的回调(回调的地狱) 5 创建一个大而完整的应用程序 ...
- Qt5 Crash When Open File With QFileDialog
问题描述 在使用Qt的QFileDialog这个类,来进行文件的打开和选择的时候, 就在调用的时候, 总是发生崩溃. 而且没有任何的提示性的信息. 而且崩溃的概率很高. 也有不崩溃的情况. 这个问题, ...
- Bower是什么?
一.简介 Bower是一个客户端技术的软件包管理器,它可用于搜索.安装和卸载如JavaScript.HTML.CSS之类的网络资源.其它一些建立在Bower基础之上的开发工具,如YeoMan和Grun ...
- Struts2.X——搭建
今天是我第一次用博客,虽然还有好多的不懂,但是我还是会努力的把自己学到的写下来,分享给大家: 一,SSH框架中的struts2的搭建流程 1.在搭建struts2之前,我们首先要有struts2的ja ...
- hibernate学习笔记之四 Hibernate的增删改查
采用JUnit测试,继承TestCase import java.util.Date; import junit.framework.TestCase; import org.hibernate.Se ...
- c#设计模式-组合模式
在软件开发过程中,我们经常会遇到处理简单对象和复合对象的情况,例如对操作系统中目录的处理就是这样的一个例子,因为目录可以包括单独的文件,也可以包括文件夹,文件夹又是由文件组成的,由于简单对象和复合对象 ...
- Execute Sql Task 的Result DataSet如何返回
Execute Sql Task的Result DataSet 主要有以下四种,当Execute Sql Task返回结果之后,需要使用SSIS Variable 来接收数据. 例子中使用的数据表代码 ...