473,406 Members | 2,377 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,406 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 963

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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.