Hi, I am totally new to C# and doing a retraining.
Today I walked into a little problem I can't solve yet..
I did a tutorial from Pragmtech on youtube:
https://www.youtube.com/watch?v=SgHYVPKJRX8&list=PLAC325451207E3105&index=102
The problem is that when running the code it doesn't show the text "processing file. Please wait".
I hope someone can help me out. Thx!
- private int CountCharacters()
- {
- int count = 0;
- using (StreamReader reader = new StreamReader(@"C:\Users\TTTG11133.NOA\Documents\JeroenK\Test\AsyncAwaitPragmTech101\data.txt"))
- {
- string content = reader.ReadToEnd();
- count = content.Length;
- Thread.Sleep(5000);
- }
- return count;
-
- }
-
-
-
- private async void btnProcess1_Click(object sender, RoutedEventArgs e)
- {
-
-
- Task<int> task = new Task<int>(CountCharacters);
- task.Start();
-
- lblCount.Text = "processing file. Please wait...";
- int count = await task;
-
- lblCount.Text = count.ToString() + "characters in file";
- myTextBox.Text = "jeroen";
-
- }
-
- private void btnProces2_Click(object sender, RoutedEventArgs e)
- {
-
- int count = 0;
-
- Thread thread = new Thread(() => { count = CountCharacters(); });
- thread.Start();
-
- myTextBlock2.Text = "processing file. Please wait...";
- thread.Join();
- myTextBlock2.Text = count.ToString();
-
-
-
-
- }