TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jeroen Kolk
NA
11
782
Threads.join() doesn't work like expected
Nov 5 2017 8:00 AM
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;
}
//Async await with blocking (using task)
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();
// The next string should appear after 5 sec.
myTextBlock2.Text = count.ToString();
}
Reply
Answers (
3
)
Problem commit to GIT repos
how to edit the tags of mp3 file?