久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

AsyncCTP:創建一個 IAwaitable 的類

AsyncCTP: Creating a class that is IAwaitable(AsyncCTP:創建一個 IAwaitable 的類)
本文介紹了AsyncCTP:創建一個 IAwaitable 的類的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我發現自己想要實現一個 IAwaitable 類(實現異步調用而不阻塞線程的東西).

I found myself wanting to implement an IAwaitable class (something that implements asynchronous calls without blocking threads).

我安裝了最新版本的 AsyncCTP,編譯器說我需要一個 IsCompleted() 成員.好的,所以 CTP 預覽已經移動了一點(我明白了,就像預覽一樣)

I've got the most recent version of AsyncCTP installed, and the compiler is saying that I need an IsCompleted() member. Okay, so the CTP preview has moved on a little bit (I get that, like it's a preview)

問題:現在AsyncCTP 語言擴展期望什么接口?

Question: What interface are the AsyncCTP language extensions expecting now?

問題: 在所有這些中,我假設我可以通過 lamda/delegate 向IAwaitable"發出信號?這可能嗎?我們叫 EndAwait 嗎?智能感知建議您調用 EndAwait 來檢索結果......所以這聽起來不對.有什么想法嗎?

Question: In all this I'm assuming that I can signal to the "IAwaitable" via a lamda/delegate? Is this possible? Do we call EndAwait? The intellisense suggests that you call EndAwait to retrieve the result... so that doesn't sound right. Any ideas?

到目前為止,我發現的所有示例都針對 AsyncCTP 庫已經實現的功能,例如:

All of the examples I've found so far are for features that the AsyncCTP library has already implemented such as:

  await new WebClient().DownloadStringTaskAsync(uri).ConfigureAwait(false);

來自 101 AsyncSamplesCS

背景:

我發現自己在 Jon Skeets 頁面上(再次)查看 這個例子

I find myself on Jon Skeets page (again) looking at this example

using System;

class Test
{
    static async void Main()
    {
        await new Awaitable();
    }
}

class Awaitable
{
    public Awaiter GetAwaiter()
    {
        return new Awaiter();
    }
}

class Awaiter
{
    public bool BeginAwait(Action continuation)
    {
        return false;
    }

    public int EndAwait()
    {
        return 1;
    }
}

推薦答案

隨著 SP1 的更新,您需要:

With the SP1 refresh, you need:

  • 某些 GetAwaiter() 方法(可能但不一定是擴展方法)返回某些內容(在您的示例中為 Awaiter),其中包含以下所有內容:
    • 一個 bool IsCompleted 屬性 (get)
    • A void OnCompleted(Action callback)
    • 一個 GetResult() 方法,它返回 void,或等待操作的期望結果
    • Some GetAwaiter() method (possibly but not necessarily an extension method) that returns something (Awaiter in your example) with all of:
      • A bool IsCompleted property (get)
      • A void OnCompleted(Action callback)
      • A GetResult() method which returns void, or the desired outcome of the awaited operation

      但是,我建議您查看TaskCompletionSource - 我看了這個,結果出來了- 執行我的幼稚實現(此處;已過時).你也可以將它用于 void 任務,通過使用類似 TaskCompletionSource 的東西(并利用 Task也是一個無類型的Task).

      However, I suggest you look at TaskCompletionSource<T> - I looked at this, and it out-performed my naive implementation (here; obsolete). You can also use it for void tasks, by using something like a TaskCompletionSource<bool> (and exploit the fact that the Task<bool> is also an untyped Task).

      這篇關于AsyncCTP:創建一個 IAwaitable 的類的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

      【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Is there a C# library that will perform the Excel NORMINV function?(是否有執行 Excel NORMINV 函數的 C# 庫?)
Select x random elements from a weighted list in C# (without replacement)(從 C# 中的加權列表中選擇 x 個隨機元素(無需替換))
Create a summary description of a schedule given a list of shifts(給定輪班列表,創建時間表的摘要描述)
C# Normal Random Number(C# 普通隨機數)
Standard deviation of generic list?(通用列表的標準偏差?)
How can I make a ksoap2 call in async task?(如何在異步任務中進行 ksoap2 調用?)
主站蜘蛛池模板: 欧美一区二区三区视频在线观看 | 国产视频精品免费 | 成人在线一区二区 | 日韩 欧美 二区 | 又黄又爽的网站 | 午夜免费影视 | 欧美福利网站 | 99久久免费精品国产免费高清 | 亚洲一区二区三区四区五区中文 | 亚洲欧美精品在线 | 久久9精品 | 色吊丝在线 | 精品不卡| 91视频播放| 红色av社区| 男女在线免费观看 | 美女视频网站久久 | 中文字幕免费在线 | 久久99精品久久久久久青青日本 | 亚洲国产精品一区二区久久 | 亚洲国产一区二区三区在线观看 | 三级视频在线观看 | 丁香五月网久久综合 | 91久久精品 | 美国一级黄色片 | 欧美区在线 | 日韩中文字幕高清 | 亚洲视频免费在线观看 | 精品久久久久久亚洲国产800 | 亚洲欧美精品在线观看 | 国产精品久久久久久久久久久久久久 | 精品中文字幕一区二区 | 亚洲免费精品一区 | 国产精品久久久久久亚洲调教 | 在线视频亚洲 | 国产精品国产三级国产aⅴ无密码 | 国产良家自拍 | www国产成人 | 国产美女一区二区 | 狠狠躁躁夜夜躁波多野结依 | 亚洲三级在线观看 |