Good practice when waiting for an event

  • Thread starter Thread starter arun.hallan
  • Start date Start date
A

arun.hallan

I need the following functionality.

public Object RunValuation
{
run process that writes to database

check the database every second to check if results are ready

when results are ready, retrieve them and return object with data
in it

}


I'm wondering how to poll the database every second? I could use a
timer, but then how do i return the object if the timer has to call
another method?

The only way i can think of is having a neverending loop, that breaks
when the results are ready. There could be a Thread.Sleep in the loop
to make the thread wait a second.

Can anyone tell me what the best practice is for something like this?

Thanks,
Arun
 
The only way i can think of is having a neverending loop, that breaks
when the results are ready. There could be a Thread.Sleep in the loop
to make the thread wait a second.

I don't see any problem with this... except you *should* have a timeout in
the loop so if the answer never appears you don't lock the thread. You
might want to run this in the background, as well.

-mdb
 
Back
Top