上一页 1 ··· 3 4 5 6 7 8 9 下一页
摘要: 要些异步方法要注意一下几点: 异步方法的返回值有三种: 1.没有任何返回值的void 2.返回一个Task任务的Task,可以获得该异步方法的执行状态 3.返回Task<T> 可以获得异步方法执行的结果和执行状态 下面看示例: 如果你认为你的异步任务不需要知道它的执行状态(是否出现异常等)可以使用没 阅读全文
posted @ 2018-05-01 11:10 C_supreme 阅读(583) 评论(0) 推荐(0) 编辑
摘要: 这次来理解一下异步方法与线程之间的关系 新建一个控制台程序 代码如下 看一下执行结果 可以看到 调用者线程在执行到await这里时会开启一个新的线程去执行await方法,并且立即返回,所以在await DoWork();方法前和TestDoWorkAsync();方法后都是由主线程去执行,而异步方法 阅读全文
posted @ 2018-04-30 19:38 C_supreme 阅读(342) 评论(0) 推荐(0) 编辑
摘要: C#5.0引入async和await关键字实现方法的异步调用。 直接进入正题。 async只是一个标识符,并没有实际的用途,只是用于表明某个方法是异步方法,在方法前面加上async 表示该方法为一个异步方法,方法体内部会有一个await关键字。如果没有await关键字编译器会给出警告。 await则 阅读全文
posted @ 2018-04-30 19:13 C_supreme 阅读(531) 评论(0) 推荐(0) 编辑
摘要: 概念:TPL( Task Parallel Library) 任务并行库 使用Task类执行多线程操作要比直接使用自己手工创建Thread效率高很多。 默认情况下,TPL使用线程池中的线程执行Task,但是工作结束之后,调用者线程怎么取回执行线程的工作结果呢? 这里有三种方法: 1.使用经典的线程同 阅读全文
posted @ 2018-04-22 19:42 C_supreme 阅读(225) 评论(0) 推荐(0) 编辑
摘要: 在刷LeetCode时遇到了一题可以用到分治思想的题目,刚好前段时间有看到过关于分治思想的讲解,但是不是很理解,这里再学习一次。 分而治之(divide and conquer,D&C)——一种著名的递归式问题解决方法。 使用分治解决问题的过程包括两个步骤: 1.找出基线条件,这种条件必须尽可能简单 阅读全文
posted @ 2018-04-20 21:41 C_supreme 阅读(696) 评论(0) 推荐(0) 编辑
摘要: Description Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. E 阅读全文
posted @ 2018-04-20 21:23 C_supreme 阅读(255) 评论(0) 推荐(0) 编辑
摘要: Description Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were in 阅读全文
posted @ 2018-04-20 11:15 C_supreme 阅读(161) 评论(0) 推荐(0) 编辑
摘要: Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another ar 阅读全文
posted @ 2018-04-19 16:35 C_supreme 阅读(153) 评论(0) 推荐(0) 编辑
摘要: Description Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length. Do not alloca 阅读全文
posted @ 2018-04-19 16:05 C_supreme 阅读(114) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have ex 阅读全文
posted @ 2018-04-19 12:09 C_supreme 阅读(96) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 下一页