Skip to content

Commit be1699b

Browse files
authored
Update threading code to match article (#6277)
1 parent 8854b12 commit be1699b

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed
5 Bytes
Binary file not shown.

wpf/Threading/Weather/net48/csharp/Weather.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ private async void FetchButton_Click(object sender, RoutedEventArgs e)
2020
((Storyboard)Resources["HideWeatherImageStoryboard"]).Begin(this);
2121

2222
// Asynchronously fetch the weather forecast on a different thread and pause this code.
23-
string weather = await FetchWeatherFromServerAsync();
23+
string weather = await Task.Run(FetchWeatherFromServerAsync);
2424

2525
// After async data returns, process it...
2626
// Set the weather image
14 Bytes
Binary file not shown.

wpf/Threading/Weather/net48/vb/Weather.xaml.vb

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ Public Class Weather
1111
DirectCast(Resources("HideWeatherImageStoryboard"), Storyboard).Begin(Me)
1212

1313
' Asynchronously fetch the weather forecast on a different thread and pause this code.
14-
Dim Weather As String = Await FetchWeatherFromServerAsync()
14+
Dim weatherType As String = Await Task.Run(AddressOf FetchWeatherFromServerAsync)
1515

1616
' After async data returns, process it...
1717
' Set the weather image
18-
If Weather = "sunny" Then
18+
If weatherType = "sunny" Then
1919
weatherIndicatorImage.Source = DirectCast(Resources("SunnyImageSource"), ImageSource)
2020

21-
ElseIf Weather = "rainy" Then
21+
ElseIf weatherType = "rainy" Then
2222
weatherIndicatorImage.Source = DirectCast(Resources("RainingImageSource"), ImageSource)
2323

2424
End If
@@ -30,7 +30,7 @@ Public Class Weather
3030
' Update UI text
3131
fetchButton.IsEnabled = True
3232
fetchButton.Content = "Fetch Forecast"
33-
weatherText.Text = Weather
33+
weatherText.Text = weatherType
3434
End Sub
3535

3636
Private Async Function FetchWeatherFromServerAsync() As Task(Of String)

0 commit comments

Comments
 (0)