共用方式為


Async.Start 方法 (F#)

更新:2010 年 7 月

在執行緒集區中啟動非同步計算。 不要等待結果。

命名空間/模組路徑: Microsoft.FSharp.Control

組件:FSharp.Core (在 FSharp.Core.dll 中)

// Signature:
static member Start : Async<unit> * ?CancellationToken -> unit

// Usage:
Async.Start (computation)
Async.Start (computation, cancellationToken = cancellationToken)

參數

  • computation
    型別:Async<unit>

    要非同步執行的計算。

  • cancellationToken
    型別:CancellationToken

    要與計算產生關聯的取消語彙基元。 如果未提供一個取消語彙基元,則會使用預設的取消語彙基元。

備註

如果未提供取消語彙基元,則會使用預設的取消語彙基元。

範例

下列程式碼範例會示範如何開始非同步的計算執行緒集區上。

open System.Windows.Forms

let bufferData = Array.zeroCreate<byte> 100000000

let async1 =
     async {
       use outputFile = System.IO.File.Create("longoutput.dat")
       do! outputFile.AsyncWrite(bufferData) 
     }


let form = new Form(Text = "Test Form")
let button = new Button(Text = "Start")
form.Controls.Add(button)
button.Click.Add(fun args -> Async.Start(async1))
Application.Run(form)

平台

Windows 7、Windows Vista SP2、Windows XP SP3、Windows XP x64 SP2、Windows Server 2008 R2、Windows Server 2008 SP2、Windows Server 2003 SP2

版本資訊

F# 執行階段

支援版本:2.0、4.0

Silverlight

支援版本:3

請參閱

參考

Control.Async 類別 (F#)

Microsoft.FSharp.Control 命名空間 (F#)

變更記錄

日期

History

原因

2010 年 7 月

加入程式碼範例。

資訊加強。