Invoke BeginInvoke EndInvoked的使用 简单的线程同步
来源:互联网 发布:ogame银河帝国源码 编辑:程序博客网 时间:2024/05/21 09:16
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;namespace _11._3._1{ class Program { public delegate int FooDelegate(string s); static void Main(string[] args) { Console.WriteLine("主线程" + Thread.CurrentThread.ManagedThreadId); FooDelegate fooDelegate = Foo; IAsyncResult result = fooDelegate.BeginInvoke("Hello World.", null, null); Console.WriteLine("主线程继续执行..."); Console.WriteLine("结果是" ); //当使用BeginInvoke异步调用方法时,如果方法未执行完,EndInvoke方法就会一直阻塞,直到被调用的方法执行完毕,线程同步。 int n = fooDelegate.EndInvoke(result); Console.WriteLine("回到主线程" + Thread.CurrentThread.ManagedThreadId); Console.WriteLine("结果是" ); Console.ReadKey(true); } public static int Foo(string s) { Console.WriteLine("函数所在线程" + Thread.CurrentThread.ManagedThreadId); Console.WriteLine("异步线程开始执行:" + s); Thread.Sleep(1000); return s.Length; } }}
1、声明委托
2、委托实例化
3、用委托异步线程 BeginInovke
4、阻塞主线程 EndInovke
阅读全文
0 0
- Invoke BeginInvoke EndInvoked的使用 简单的线程同步
- Invoke或者BeginInvoke的使用
- Invoke或者BeginInvoke的使用
- Invoke和BeginInvoke的使用
- Invoke和BeginInvoke的使用
- Invoke或者BeginInvoke的使用(转)
- Invoke和BeginInvoke的使用(转载)
- Invoke和BeginInvoke的使用(转载)
- Invoke和BeginInvoke的使用(转载)
- Invoke()/BeginInvoke()的区别
- C#中Invoke与BeginInvoke的区别(另附使用循环创建多个线程)
- Control的Invoke和BeginInvoke 是相对于支线线程
- Control的Invoke和BeginInvoke 是相对于支线线程
- Control的Invoke和BeginInvoke 是相对于支线线程
- control 的invoke 和begininvoke
- Control的Invoke和BeginInvoke
- Control的Invoke和BeginInvoke
- Control的Invoke和BeginInvoke
- 【Redis学习】:redis持久化
- c印记(十四):跨平台线程封装
- 使用pytorch准备自己的数据
- 简单实现一个自定义view的ProgressBar
- 关于Maven构建项目或者update项目时jdk变为1.5解决方案,亲测有效。
- Invoke BeginInvoke EndInvoked的使用 简单的线程同步
- 成功人的五个步骤
- 找到焦点onfocus和失去焦点onblur、以及onchange
- Python生成PASCAL VOC格式的xml标注文件
- 找到一本不错的Linux电子书,附《Linux就该这么学》章节目录。
- 找到一本不错的Linux电子书,附《Linux就该这么学》章节目录
- 创建linux0.11文件系统
- Spring AOP 之AspectJ注解和XML配置两种实现(Maven构建)
- Windows开机自动启动某些软件