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
bram 0
NA
11
0
Thread problem
May 7 2004 12:44 PM
Hello, I want a separate thread to handle serial communication in a simple way: Forever do the following: - Send message - Wait for reply - Act on it I'm using events for the reply because a while(!received) type solution is very slow when there are a lot of threads. This is basically what I'm doing: class Handler { Thread thread = new Thread(new ThreadStart(work)); Reply reply; public Handler() { commObject.Reply += new EvenReply(receiveReply); thread.start(); } public void work() { while(true) { sendCommand(); thread.Suspend(); // wait for reply handleReply(); } } public void receiveReply(Reply r) { this.reply = r; thread.Resume(); } } Unfortunately, this causes problems. Sometimes the event is already raised before the thread is stopped and I can't use a critical sections because this will prevent the thread from ever being resumed. Any ideas on how to do this?!
Reply
Answers (
0
)
Killing print jobs
How can I create object each class