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

AsyncCTP:創(chuàng)建一個 IAwaitable 的類

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

問題描述

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

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

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

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)

問題:現(xiàn)在AsyncCTP 語言擴展期望什么接口?

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

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

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?

到目前為止,我發(fā)現(xiàn)的所有示例都針對 AsyncCTP 庫已經(jīng)實現(xiàn)的功能,例如:

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

背景:

我發(fā)現(xiàn)自己在 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() 方法(可能但不一定是擴展方法)返回某些內(nèi)容(在您的示例中為 Awaiter),其中包含以下所有內(nèi)容:
    • 一個 bool IsCompleted 屬性 (get)
    • A void OnCompleted(Action callback)
    • 一個 GetResult() 方法,它返回 void,或等待操作的期望結(jié)果
    • 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 - 我看了這個,結(jié)果出來了- 執(zhí)行我的幼稚實現(xiàn)(此處;已過時).你也可以將它用于 void 任務(wù),通過使用類似 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).

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

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

相關(guān)文檔推薦

Is there a C# library that will perform the Excel NORMINV function?(是否有執(zhí)行 Excel NORMINV 函數(shù)的 C# 庫?)
Select x random elements from a weighted list in C# (without replacement)(從 C# 中的加權(quán)列表中選擇 x 個隨機元素(無需替換))
Create a summary description of a schedule given a list of shifts(給定輪班列表,創(chuàng)建時間表的摘要描述)
C# Normal Random Number(C# 普通隨機數(shù))
Standard deviation of generic list?(通用列表的標(biāo)準(zhǔn)偏差?)
How can I make a ksoap2 call in async task?(如何在異步任務(wù)中進行 ksoap2 調(diào)用?)
主站蜘蛛池模板: 国产成人在线视频 | 国产伦精品一区二区三区视频黑人 | 日日操夜夜撸 | 中文字幕在线免费视频 | 国产主播一区二区 | 亚洲精品a | 久操不卡 | 欧美日韩在线一区二区 | 欧美三级韩国三级日本三斤在线观看 | 极品淫少妇 | 青草av在线| 国产在线观看网站 | 欧美日韩国产在线观看 | 国产伦精品一区二区三区照片 | 亚洲黄色影院 | 亚洲精品91 | 国产精品欧美在线 | 欧美日韩成人在线观看 | 亚洲福利专区 | 91久久国产综合久久91精品网站 | 高清免费av| 中文字幕在线看片 | 日韩天堂网| 免费毛片观看 | 亚洲精品成人网 | 不卡视频在线观看 | 久草视频在线播放 | 欧美在线亚洲 | 美日韩一区 | 日韩视频免费大全中文字幕 | 草草在线观看 | 成人午夜视频在线观看 | 日韩成人三级 | 少妇在线观看 | 国语对白做受69 | 午夜av网站| 免费91网站| 精品视频国产 | 欧美日韩国产在线 | 一区二区三区在线播放 | 亚洲性天堂 |