Re: VB6 (formless) Timer class




"2b|!2b==?" <user@xxxxxxxxxxxxxx> wrote

What I am trying to do is to use a timer to simulate asynchronous
processing of events. So I want different 'event classes' each of which
handles different events. Something like this:

Does anyone know how I may do this ?

....
One other question relating to this is that of the lifespan of the
EventClass - once the timer has fired and the custom processing has been
done, the EventClass has done its job - and it needs to be 'released'
from memory - since there is no explicit 'delete' in VB:

i). At waht point will the EventClass be collected by the garbage
collector ?
ii). Can I force the object to be 'freed' once it has done its job? -
otherwise I could potentially be faced with several thousand 'dead
objects after a few hours of running

There is no need to re-invent the wheel. VB ships with a Timer control
for use on its forms. You can use a form and timer without having to
show the form to the user. Doing so will let you use familiar code to
handle your task.

What you need to be concerned about is the thread used to execute
your tasks. If you sit and wait for incoming calls, things will go smoothly,
until you start responding to those calls. If you send a class off to do
some 'asyncronous' task, then part of your application's processing has
to include the time necessary to do that task. If that task is processor
intensive, then it wil effect your ability to respond to incoming calls.

After launching some number of those intensive tasks all trying to run at
the same time, you will find you are no better off than if you'd responded
to the calls directly. That is because your entire program can only execute
*one line of code at a time*.

If execution is taking place in a CPU hogging routine, (no DoEvents) then all
other processing in your application grinds to a halt until that routine has ended.
That includes the code you want responding to incoming calls.

Since you can only execute one line of code at a time, tasks (routines) that
have no DoEvents are going to run to completion, before any other task
you may have started. In essence you will have built a queue where the first
tasks in run to completion, ahead of any other task created.

If the 'queue' response is acceptable to you, why not build it as a queue,
(a bit simpler) instead of the not-so-asycnronous multiple tasks?

If the queue method is not acceptable, and you really want those tasks to
run asyncronously, then you need to give them their own thread, their own
process, in which to complete their task. Again, you need not re-invent the
wheel, VB's ActiveX exe projects run their own process and can be created
and controlled from your VB application.

So, in a nutshell, what is it you really want to do?

LFS



.



Relevant Pages

  • Re: VB6 (formless) Timer class
    ... That is because your entire program can only execute ... other processing in your application grinds to a halt until that routine has ended. ... That includes the code you want responding to incoming calls. ... If the 'queue' response is acceptable to you, why not build it as a queue, ...
    (microsoft.public.vb.general.discussion)
  • Re: Single producer, "one-shot" work queue implementation, no lock on queue.
    ... usec for just calling execute() directly). ... overhead that's closer to 5nsec than 5usec. ... where there's only a single item in the queue. ... virtual void Execute() = 0; ...
    (comp.programming.threads)
  • Re: Do I need a RTOS?
    ... place, everything is empty ... ... the queue and requesting that I always keep some task in the queue. ... It is there that I call the execute function, over and over, pumping ... timer event, of course. ...
    (comp.arch.embedded)
  • Re: collecting results in threading app
    ... but execute one at the time'. ... Could a Queue help me there? ... You can take a look at papyros, a small package I wrote for hiding ... # some exception was raised when executing this job ...
    (comp.lang.python)
  • Re: Do I need a RTOS?
    ... Avail slots are by nature empty correct? ... in the avail queue, as I earlier defined them to be. ... head-pointers are equal to each other, the avail-queue is full and the ... decide to execute them is another issue. ...
    (comp.arch.embedded)

Quantcast