私は Visual Studio 2010 を使用しているため、async と await を使用するためにVisual Studio Async CTP (バージョン 3)をインストールしました。含まれているサンプル「AsnycSamplesVB」を確認しました。これらのサンプルはすべて正常に動作します。しかし、「AsyncResponsiveCPURun」などを新しいコンソール アプリケーションにコピーすると、コンパイルされますが、最初の行 (「Processing data...」) しか表示されず、停止します。ProcessDataAsync を 1 回呼び出しますが、出力はありません...? 私が間違っていることはありますか?これが私のコンソール アプリケーションの完全なコードです。Sub Main の呼び出しを除いて、すべて Microsoft のサンプルからコピーしたものです。
Module Module1
Sub Main()
AsyncResponsiveCPURun()
End Sub
Public Async Function AsyncResponsiveCPURun() As Threading.Tasks.Task
Console.WriteLine("Processing data... Drag the window around or scroll the tree!")
Console.WriteLine()
Dim data As Integer() = Await ProcessDataAsync(GetData(), 16, 16)
Console.WriteLine()
Console.WriteLine("Processing complete.")
End Function
Public Function ProcessDataAsync(ByVal data As Byte(), ByVal width As Integer, ByVal height As Integer) As Threading.Tasks.Task(Of Integer())
Return Threading.Tasks.TaskEx.Run(
Function()
Dim result(width * height) As Integer
For y As Integer = 0 To height - 1
For x As Integer = 0 To width - 1
Threading.Thread.Sleep(10) ' simulate processing cell [x,y]
Next
Console.WriteLine("Processed row {0}", y)
Next
Return result
End Function)
End Function
Public Function GetData() As Byte()
Dim bytes(0 To 255) As Byte
Return bytes
End Function
End Module