zoukankan      html  css  js  c++  java
  • c# task

    Task Parallel Library: 1 of n

    http://www.codeproject.com/Articles/152765/Task-Parallel-Library-of-n

    Task 与Thread, lambda,  action,funct之间有什么关联。

    Task相比Thread提供了什么方便之处。

    Thread

    1. 创建费时间,占用内存与CPU的资源

    For example, when a new Thread is started in .NET, there is a whole process that goes with that, such as creating queues, thread local storage, managing the Thread's lifecycle etc. This takes time

    ThreadPool

    1. ThreadPool 免去了创建thread的时间,用户直接将work item 委托给ThreadPool去安排其内部的线程调用。

    2. 但classic threading ThreadPool,当一个work item已经在执行当中,用户不能去直接关闭,想得到其的结果也是很直接。

    However, even using the classic threading ThreadPool, there were problems in that you could not cancel a work item once it has been queued with the ThreadPool, or get a return result that easily. It just doesn't read that well either. There is an excellent article here on CodeProject that tackles some of these issues: Smart ThreadPool, which is pretty excellent actually. However, the new TPL infrastructure has got all these problems covered, and many many more useful features in my opinion.

    Task

    1. the new TPL infrastructure has got all these problems covered, and many many more useful features in my opinion

    Task 继承了ThreadPool的优点,解决了ThreadPool的问题。其本质也可以讲Smart ThreadPool

    2. A TPL Task actually uses the ThreadPool internally.

    Task, ThreadPool, Thread, Scheduler

    It is worth mentioning that Tasks are merely wrappers for passing a delegate of work to be done, also storing state, exceptions, and continuations amongst others. That work may or may not be done by the threadpool, and as already stated, that will depend upon the scheduler used.

    常用的使用场景

    Tasks also seem to be more inline with how people think about things. For instance, imagine this scenario: "I want to call a Web Service and have it return a List<int>". Using a TPL Task, I would create a Task<List<int>> and get it to call some service in its payload delegate (which will use the ThreadPool) that returned me a List<int>.

    Task与UI Thread

    reate/cancel Tasks and handle Exceptions

  • 相关阅读:
    React-精华版
    国内优秀npm镜像推荐及使用
    GitHub 配置指南
    Nodejs之WebSocket
    js验证连续两位数字递增或递减和连续三位数字相同
    JS魔法堂:LINK元素深入详解
    phpstorm将多个int数字拼接成字符串
    php中使用curl来post一段json数据
    MySQL索引使用:字段为varchar类型时,条件要使用''包起来
    MySQL中enum类型数据,要传入字符串
  • 原文地址:https://www.cnblogs.com/pengxinglove/p/5452799.html
Copyright © 2011-2022 走看看