473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Waiting for events

I have a long subprocedure that is responsible for controlling a process
on a machine. Essentially, the subprocedure is called when a "Start"
button is pressed and only exits once the process is finished (or
aborted). The process is fairly complicated and involves quite a few
steps. It could look something like this (in VB):

Private Sub ProcessRun()

DigitalOutput(1) = Off
Do While DigitalInput(1) = Off
Application.DoEvents()
Loop

XAxis.MoveTo(3.5)
Do While XAxis.MoveDone = False
Application.DoEvents()
Loop

' etc.

End Sub

only much more complicated. As you can see, I'm using Do While loops
with DoEvents() stuck in the middle to monitor the machine's state. This
works but I can't help thinking this is the wrong way to do things.
Surely there must be a way to apply the event-driven philosophy of
Windows to this process.

So what mechanism should I be looking into to have events raised by my
hardware interface classes (Axes controllers, I/O communications, etc.)
control the progress of ProcessRun()? I picture the following:

Private Sub ProcessRun()

DigitalOutput(1) = Off
WaitForInputOn(1) ' <-- Thread pauses here until Input(1) turns on

XAxis.MoveTo(3.5)
WaitForAxisDone(XAxis) ' <-- Thread pauses here until move is done

' etc.

End Sub

Elegant and resource sparing (I presume). So any suggestions as to how I
can realize this?

I've been looking at ManualEvent and AutoResetEvent. Maybe triggering
one of these from the appropriate event handler. Am I on the right
track?

Joel Moore
Jul 21 '05 #1
0 962

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

44
by: Charles Law | last post by:
Hi guys. I'm back on the threading gig again. It's the age-old question about waiting for something to happen without wasting time doing it. Take two threads: the main thread and a worker...
3
by: Douwe | last post by:
I'm trying to write a piece of C code that has two threads: The first thread waits for a socket connection. The second thread is in a continues cycle waiting for an period of time (lets say 500 ms)...
4
by: Andreas Müller | last post by:
Hi all, I need to wait for the user to click the mouse: // some code before WaitForMouseClick();// Wait until the user clicks the mouse // go on doing something Under Win32 using C++, you...
11
by: avivgur | last post by:
Hello, I have devised a console application that uses a System.Timers.Timer and its Elapsed event. The problem is that I want the program to continue to run so that each time the event is raised,...
1
by: Mike | last post by:
Hello, Here is my challenge. I have a thread awaiting events being sent via Queue. Currently I am checking the count and if there is a count, Dequeue() the next object and process it. By...
20
by: Charles Law | last post by:
Consider the following scenario: A data packet is sent out of a serial port and a return packet is expected a short time later. The application sending the packet needs to send another packet...
0
by: Joel Moore | last post by:
I have a long subprocedure that is responsible for controlling a process on a machine. Essentially, the subprocedure is called when a "Start" button is pressed and only exits once the process is...
7
by: emer.kurbegovic | last post by:
I wonder if I can wait for the "events/notifications" from sql 2005 and then perform some action when the "event/notification" has been sent. example: i have a small table with some statistical...
2
by: studentGrammer | last post by:
working on some pageant scoring program and ran into big problem. there are three events in the pageant and after the second, the top3 contestants (finalists) are chosen. the thing is i need all the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.