Async.Ignore<'T> 方法 (F#)
更新:2010 年 7 月
建立會執行所指定計算並忽略其結果的非同步計算。
命名空間/模組路徑: Microsoft.FSharp.Control
組件:FSharp.Core (在 FSharp.Core.dll 中)
// Signature:
static member Ignore : Async<'T> -> Async<unit>
// Usage:
Async.Ignore (computation)
參數
computation
型別:Async<'T>輸入計算。
傳回值
相當於輸入計算但會忽略結果的計算。
範例
下列程式碼範例說明如何使用 Async.Ignore。
open System
open System.IO
let writeToFile filename numBytes =
async {
use file = File.Create(filename)
printfn "Writing to file %s." filename
do! file.AsyncWrite(Array.zeroCreate<byte> numBytes)
}
let readFile filename numBytes =
async {
use file = File.OpenRead(filename)
printfn "Reading from file %s." filename
// Throw away the data being read.
do! file.AsyncRead(numBytes) |> Async.Ignore
}
let filename = "BigFile.dat"
let numBytes = 100000000
writeToFile filename numBytes
|> Async.RunSynchronously
readFile filename numBytes
|> Async.RunSynchronously
平台
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
請參閱
參考
Microsoft.FSharp.Control 命名空間 (F#)
變更記錄
日期 |
History |
原因 |
---|---|---|
2010 年 7 月 |
加入程式碼範例。 |
資訊加強。 |