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
wei1ec
NA
3
0
Repeated results when using multithread
Jul 14 2004 2:45 PM
Hi, I have two classes for this example, bascially I want to pass a variable to another class and print it out, and then keep updating it. I do it like this: class1: NewClass nc = new NewClass(); for (int i = 0; i < 100; i++) { nc.SetVariable = i.ToString(); Thread t = new Thread(new ThreadStart(nc.Run)); t.Start(); } class2 (name: NewClass): private string var; public string SetVariable { set { var = value; } } public void Run() { Console.WriteLine(var); } It'll repeat some values, and it doesn't even print out all the numbers 0-99... Why is this happening? How can I fix it? Thank you for reading!
Reply
Answers (
1
)
multithread c# soscket server
Windows Form Threading Problem in VB.NET