当前位置: 首页 > news >正文

做网站用什么源码投资管理公司注册

做网站用什么源码,投资管理公司注册,企业网站优化技巧,高端制作网站服务使用异步方式调用同步方法,在此我们使用异步编程模型(APM)实现 1、定义异步委托和测试方法 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Task…

使用异步方式调用同步方法,在此我们使用异步编程模型(APM)实现
1、定义异步委托和测试方法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;namespace ApmAsyncApp
{public delegate string TestMethodAsyncCaller(int callDuration, out int threadId);/// <summary>internal class AsyncDemo{/// 执行异步调用的方法/// </summary>/// <param name="callDuration"></param>/// <param name="threadId"></param>/// <returns></returns>public string TestMethod(int callDuration,out int threadId){Console.WriteLine("Test method begins:");Thread.Sleep(callDuration);threadId=Thread.CurrentThread.ManagedThreadId;return String.Format("Call time was {0}",callDuration);}}
}

2、使用 EndInvoke 等待异步调用

static void Main(string[] args){int threadId;//创建测试类AsyncDemo asyncDemo = new AsyncDemo();//创建委托TestMethodAsyncCaller caller = new TestMethodAsyncCaller(asyncDemo.TestMethod);//初始化异步调用IAsyncResult result = caller.BeginInvoke(3000, out threadId, null, null);Thread.Sleep(0);Console.WriteLine("Main thread {0} does some work.", Thread.CurrentThread.ManagedThreadId);//调用EndInvoke检索结果string returnValue = caller.EndInvoke(out threadId, result);Console.WriteLine("The call executed on thread {0},with return value \"{1}\".", threadId, returnValue);Console.ReadLine();}

在这里插入图片描述
3、使用 WaitHandle 等待异步调用

static void Main(string[] args){int threadId;//创建测试类AsyncDemo asyncDemo = new AsyncDemo();//创建委托TestMethodAsyncCaller caller = new TestMethodAsyncCaller(asyncDemo.TestMethod);//初始化异步调用IAsyncResult result = caller.BeginInvoke(3000, out threadId, null, null);Thread.Sleep(0);Console.WriteLine("Main thread {0} does some work.", Thread.CurrentThread.ManagedThreadId);//sone to do//等待信号result.AsyncWaitHandle.WaitOne();//调用EndInvoke检索结果string returnValue = caller.EndInvoke(out threadId, result);result.AsyncWaitHandle.Close();Console.WriteLine("The call executed on thread {0},with return value \"{1}\".", threadId, returnValue);Console.ReadLine();}

在这里插入图片描述
4、对异步调用的完成情况进行轮询

static void Main(string[] args){int threadId;//创建测试类AsyncDemo asyncDemo = new AsyncDemo();//创建委托TestMethodAsyncCaller caller = new TestMethodAsyncCaller(asyncDemo.TestMethod);//初始化异步调用IAsyncResult result = caller.BeginInvoke(3000, out threadId, null, null);Thread.Sleep(0);Console.WriteLine("Main thread {0} does some work.", Thread.CurrentThread.ManagedThreadId);// 等待完成.while (result.IsCompleted == false){Thread.Sleep(250);Console.Write(".");}//调用EndInvoke检索结果string returnValue = caller.EndInvoke(out threadId, result);Console.WriteLine("The call executed on thread {0},with return value \"{1}\".", threadId, returnValue);Console.ReadLine();}

在这里插入图片描述
5、异步调用完成时执行回调方法

static void Main(string[] args){int threadId = 0;//创建测试类AsyncDemo asyncDemo = new AsyncDemo();//创建委托TestMethodAsyncCaller caller = new TestMethodAsyncCaller(asyncDemo.TestMethod);//初始化异步调用IAsyncResult result = caller.BeginInvoke(3000, out threadId, new AsyncCallback(callbackMethod), "The call executed on thread {0},with return value \"{1}\".");Console.WriteLine("Main thread {0} does some work.", Thread.CurrentThread.ManagedThreadId);Thread.Sleep(5000);Console.WriteLine("The main thread ends.");Console.ReadLine();}private static void callbackMethod(IAsyncResult ar){//检索委托.AsyncResult result = (AsyncResult)ar;TestMethodAsyncCaller caller = (TestMethodAsyncCaller)result.AsyncDelegate;//格式字符串作为状态信息被传递string formatString = (string)ar.AsyncState;int threadId = 0;//调用EndInvoke检查结果.string returnValue = caller.EndInvoke(out threadId, ar);//用格式字符串格式化输出信息Console.WriteLine(formatString, threadId, returnValue);}

在这里插入图片描述

http://www.yayakq.cn/news/957213/

相关文章:

  • 株洲网站建设的公司全国知名网
  • 济南莱芜都市网seo搜索优化是什么
  • 普陀区网站建设网络培训课程
  • 贵阳网站建设贵阳wordpress改变邮箱
  • 做门户网站起什么域名好免费做图片的网站有哪些
  • 企业网站能个人备案吗网站软文推广范文
  • 网站建设属于什么行业分类新鸿儒网站建设
  • 网站做现金抽奖 能通过四川网站建设制作
  • 影楼网站建设网站标签优化
  • 免费的源码分享网站全屋定制app量尺寸的软件
  • 碧江网站建设推广公司兴田德润活动
  • linux主机做网站中英文微信网站建设
  • 地铁工程建设论文投稿网站WordPress数据库切割
  • 简述网站建设基本过程深圳网络推广收费标准
  • 网站建设公司哪家好要选磐石网络wordpress 主题设置中文版
  • 怎么制作小视频西安seo服务商
  • 网站生成app免费wordpress 加速乐
  • 网站做适配手机要多久网站平台建设十大公司
  • 汉中 网站建设京东代运营
  • 建站类平台排行榜怎么做图片网站
  • 开网站建设公司心得wordpress默认安装目录
  • 没有网站可以做cpc吗找工作网
  • 强大的网站设计制作允许发外链的网站
  • 最好记得网站域名个人网站建站申请
  • 鞍山 网站建设网站建设论文总结
  • 百度推广做网站定安网站制作
  • 网站备案 法人wps的ppt做网站超链接
  • 网站总体规划设计说明怎么做营销型网站
  • 制作网站需要的技术洛阳凯锦腾网业有限公司
  • 网站使用的数据库主要有哪些内部网站建设软件