ich keine Asynchron-Version von GetFiles gefunden haben, aber wenn Sie für andere Async Operationen am Quelltext aussehen, sind sie wie folgt definiert:
module FileExtensions =
let UnblockViaNewThread f =
async { //let ctxt = System.Threading.SynchronizationContext.Current
do! Async.SwitchToNewThread()
let res = f()
do! Async.SwitchToThreadPool()
//do! Async.SwitchTo ctxt
return res }
type System.IO.File with
static member AsyncOpenText(path) = UnblockViaNewThread (fun() -> System.IO.File.OpenText(path))
static member AsyncAppendText(path) = UnblockViaNewThread (fun() -> System.IO.File.AppendText(path))
static member AsyncOpenRead(path) = UnblockViaNewThread (fun() -> System.IO.File.OpenRead(path))
static member AsyncOpenWrite(path) = UnblockViaNewThread (fun() -> System.IO.File.OpenWrite(path))
static member AsyncOpen(path,mode,?access,?share) =
let access = match access with Some v -> v | None -> System.IO.FileAccess.ReadWrite
let share = match share with Some v -> v | None -> System.IO.FileShare.None
UnblockViaNewThread (fun() -> System.IO.File.Open(path,mode,access,share))
static member OpenTextAsync(path) = System.IO.File.AsyncOpenText(path)
static member AppendTextAsync(path) = System.IO.File.AsyncAppendText(path)
static member OpenReadAsync(path) = System.IO.File.AsyncOpenRead(path)
static member OpenWriteAsync(path) = System.IO.File.AsyncOpenWrite(path)
static member OpenAsync(path,mode,?access,?share) = System.IO.File.AsyncOpen(path, mode, ?access=access, ?share=share)
Mit anderen Worten, die Async-Datei, Stream und WebClient Operationen sind nur Wrapper um die syncronous Operationen, so sollten Sie in der Lage sein, Ihren eigenen Wrapper um GetFiles/GetDirectories zu schreiben, wie folgt:
module IOExtensions =
type System.IO.Directory with
static member AsyncGetFiles(directory) = async { return System.IO.Directory.GetFiles(directory) }
static member AsyncGetDirectories(path) = async { return System.IO.Directory.GetDirectories(path) }
ist dies immer noch der Fall, dass .NET 4.5 mit einer Reihe neuer asynchroner APIs auskommt? Ich habe danach gesucht und es nicht gesehen. –