Control.Invoke messages: how are they buffered?

J

Jeff Stewart

I have a worker thread running a POP3 mail retriever that raises a NewEmail
event every time a message is retrieved. The NewMail handler updates a
ListView in my form with a line representing the new message.

I'm using Control.Invoke properly in the NewEmail handler, but I'm concerned
about the worker thread sending more events than can be handled by the UI
thread. There is a special sorting routine that runs every time the list is
updated. As the list fills up with hundreds of messages, this calculation
can take a long time, and during that time the worker thread is still
sending Invoke requests. Will the UI thread ever "miss" an Invoke() request
because it is preoccupied with a CPU-intensive calculation? I don't know
enough about what Invoke() actually -does- to know whether the requests are
queued, pumped, or what. I just don't want my list to be outdated because a
NewMail event was lost, due to the UI thread being too busy.
 
L

Larry Serflaten

Jeff Stewart said:
I have a worker thread running a POP3 mail retriever that raises a NewEmail
event every time a message is retrieved. The NewMail handler updates a
ListView in my form with a line representing the new message.

I'm using Control.Invoke properly in the NewEmail handler, but I'm concerned
about the worker thread sending more events than can be handled by the UI
thread. There is a special sorting routine that runs every time the list is
updated. As the list fills up with hundreds of messages, this calculation
can take a long time, and during that time the worker thread is still
sending Invoke requests. Will the UI thread ever "miss" an Invoke() request
because it is preoccupied with a CPU-intensive calculation? I don't know
enough about what Invoke() actually -does- to know whether the requests are
queued, pumped, or what. I just don't want my list to be outdated because a
NewMail event was lost, due to the UI thread being too busy.

Do some testing to see if a delayed response will drop a call. Set up a
method that sleeps for half a second and use a second thread to call it
10 times passing in the number of the call. If your delayed routine sees
all the numbers 1-10, then none were missed....

LFS
 
J

Jeff Stewart

I'd be curious to know if Windows provides any kind of indicator when/if a
dropped message occurs.

But getting back to the actual mechanism: what does Invoke() actually cause
the main thread to do? Total shot in the dark: is a message added to the
thread's pump? (If so, is there a constant somewhere that tells the capacity
of the pump?)

I seem to remember from my early Win32/MFC days that there were ways to have
Windows drop messages if other messages of the same type were also present,
effectively making Windows only respond to the most recent event of that
type. Did I imagine that?
 
J

Jeff Stewart

This is great! It's already given me an idea on something I want to do
differently. Thanks!

(Almost halfway through. :)

--
Jeff S.


Imran Koradia said:
I believe all calls are queued up just like windows messages and processed
in order. Hence, AFAIK, there shouldn't be any "dropped" calls. Here's a
blog post on this:
http://weblogs.asp.net/justin_rogers/articles/126345.aspx

Its pretty long and detailed - probably more than you asked for.


hope that helps..
Imran.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top