Execute Statement Asynchronously (FromAsync)
In This Article
Passes the appropriate BeginXxxx and EndXxxx methods (depending the current statement) to the FromAsync method of Task.Factory, launching an asynchronous operation and returning a handle to the associated Task.
#Availability
Available from the context menu or via shortcuts:
- when the caret is on a asynchronous operation call.
#Example
FileStream fs = File.Create("myfile.txt");
byte [] buffer = new byte[512];
fs.│Read(buffer, 0, buffer.Length);
Dim fs As FileStream = File.Create("myfile.txt")
Dim buffer(512) As Byte
fs.│Read(buffer, 0, buffer.Length)
Result:
FileStream fs = File.Create("myfile.txt");
byte [] buffer = new byte[512];
var t = Task<int>.Factory.FromAsync(fs.BeginRead, fs.EndRead, buffer, 0, buffer.Length, null);
t.Wait();
Dim fs As FileStream = File.Create("myfile.txt")
Dim buffer(512) As Byte
Dim t = Task(Of Integer).Factory.FromAsync(AddressOf fs.BeginRead, AddressOf fs.EndRead, buffer, 0, buffer.Length, Nothing)
t.Wait()