I've got an application that, in the main form, Starts up a thread. That
thread consists of an endless loop (a WHILE TRUE loop), at the end of each
iteration is a Sleep() command, so it will sleep for 5 seconds between each
run.
I need this thread to poll for some database changes, and update data on the
form when it does.
I've got that part working fine.
What I'm having a problem with, is when I change the value of one of the
controls on my form (in this case a combobox), I want to have it bump it out
of "sleep" mode before the 5 seconds has passed.
However, I cannot figure out how to do this.
Any ideas?
Oh, before it's suggested, I can't just reduce my sleep delay, as I don't
want to bring the database to it's knees from continually calling it.
Thanks!
-Scott 2 3625
Scott, Any ideas?
Rather then use Sleep, have you considered using a
System.Threading.AutoResetEvent object?
Your thread would call AutoResetEvent.WaitOne with a timeout value. While
your main thread would call AutoResetEvent.Set to release the thread early.
Something like (untested):
Private m_event As New AutoResetEvent(False)
Private m_wait As TimeSpan = TimeSpan.FromSeconds(5)
Public Sub WorkerThread(...)
Do While True
m_event.WaitOne(m_wait, False)
' do the database stuff
Loop
End Sub
Private Sub ComboBox_Changed(...)
m_event.Set()
End Sub
The m_event.WaitOne will wait 5 seconds or until m_event.Set is called which
ever comes first.
Hope this helps
Jay
"Scott M. Lyon" <sc******************@rapistan.BLUE.com> wrote in message
news:eA**************@tk2msftngp13.phx.gbl... I've got an application that, in the main form, Starts up a thread. That thread consists of an endless loop (a WHILE TRUE loop), at the end of each iteration is a Sleep() command, so it will sleep for 5 seconds between each run.
I need this thread to poll for some database changes, and update data on the form when it does.
I've got that part working fine.
What I'm having a problem with, is when I change the value of one of the controls on my form (in this case a combobox), I want to have it bump it out of "sleep" mode before the 5 seconds has passed.
However, I cannot figure out how to do this.
Any ideas? Oh, before it's suggested, I can't just reduce my sleep delay, as I don't want to bring the database to it's knees from continually calling it.
Thanks! -Scott
That worked wonderfully! Thanks, Jay!
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:e7**************@tk2msftngp13.phx.gbl... Scott, Any ideas? Rather then use Sleep, have you considered using a System.Threading.AutoResetEvent object?
Your thread would call AutoResetEvent.WaitOne with a timeout value. While your main thread would call AutoResetEvent.Set to release the thread
early. Something like (untested):
Private m_event As New AutoResetEvent(False) Private m_wait As TimeSpan = TimeSpan.FromSeconds(5)
Public Sub WorkerThread(...)
Do While True m_event.WaitOne(m_wait, False) ' do the database stuff Loop
End Sub
Private Sub ComboBox_Changed(...) m_event.Set() End Sub
The m_event.WaitOne will wait 5 seconds or until m_event.Set is called
which ever comes first.
Hope this helps Jay
"Scott M. Lyon" <sc******************@rapistan.BLUE.com> wrote in message news:eA**************@tk2msftngp13.phx.gbl... I've got an application that, in the main form, Starts up a thread. That thread consists of an endless loop (a WHILE TRUE loop), at the end of
each iteration is a Sleep() command, so it will sleep for 5 seconds between each run.
I need this thread to poll for some database changes, and update data on the form when it does.
I've got that part working fine.
What I'm having a problem with, is when I change the value of one of the controls on my form (in this case a combobox), I want to have it bump it out of "sleep" mode before the 5 seconds has passed.
However, I cannot figure out how to do this.
Any ideas? Oh, before it's suggested, I can't just reduce my sleep delay, as I
don't want to bring the database to it's knees from continually calling it.
Thanks! -Scott
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Harald Armin Massa |
last post by:
I need to do some synchronisations like in a cron.job
import time
from threading import Thread
class updater(Thread):
def run(self):
while True:
do_updates()
time.sleep(600)
|
by: COMfused |
last post by:
I have a thread that has a delegate function which will be called when
another process exits. This thread went to sleep, the process exits and is
supposed to call the delegate, but it did not...
|
by: Alvin Bruney |
last post by:
I'm observing that a sleeping thread changes to stopped after a while. Is
that accepted framework behavior for web applications?
My thread basically does some work, and sleeps for 60 minutes...
|
by: cmay |
last post by:
Can someone give me some guidance on this?
I am implementing a system where if a user fails the login, I am doing
a thread.sleep(random number).
If I returned the page right away, you could...
|
by: scorpion53061 |
last post by:
I have MS Word operating in a thread other than the main writing a report.
Can I tell the main thread to wait until a particular point (a sub starts)
in another thread before continuing on?
|
by: Benny Raymond |
last post by:
I have a thread that sleeps for 5 minutes once it's finished running a
method and then it repeats itself if it's supposed to (bool = true).
Prior to 2.0 I was able to resume the thread after...
|
by: Hans |
last post by:
Hi all,
Is there a way that the program that created and started a thread also stops
it.
(My usage is a time-out).
E.g.
thread = threading.Thread(target=Loop.testLoop)
thread.start() ...
|
by: many_years_after |
last post by:
Hi, pythoners:
There is a problem I couldn't dispose. I start a thread in the my
program. The thread will do something before executing time.sleep().
When the user give a signal to the main...
|
by: Mark |
last post by:
We are building a public web application that calls a web service on an
internal box. The web service runs for 5-10 minutes, does some heavy
processing, and writes to a database when it is...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |