Re: MessageBox.Show and program behaviour



I don't think so. I always coded with threads and a sleep sets the
process into the queue process but a .DoEvents get's always called
whenever the process gets back in action.
By the way, I don't think I'm getting the error now, even without the
MessageBox.Show.

Mehdi wrote:
On 14 Mar 2006 13:43:01 -0800, Nuno Magalhaes wrote:

Why does the MessageBox.Show function in the thread below changes the
program behaviour, in other words, the APListView becomes filled with
values with a call to RefreshAPListView. Without the MessageBox.Show
function, in my laptop, the code doesn't get past the inner loop where
there is a Thread.Sleep(10).

Your code is just an infinite loop where you fill your APListView, then
sleep then fill your APListView again, then sleep... This means that
without that call to MessageBox.Show, the UI thread (in which you are
executing your loop i suppose) never gets a chance to process the pending
(painting) messages in its message queue. Therefore, even though your
APListView is effecively filled, it never gets painted because you are not
letting it time to paint itslef.

When you call MessageBox.Show, the UI thread sits there doing nothing until
your click OK to close the MessageBox, which lets it time to process its
message queue messages and to paint your APListView. If you want to force
the UI thread to process all pending messages in the message queue (and
therefore force it to paint your APListView), call Application.DoEvents().
But it doesn't seem a good idea to me to put the UI thread to sleep anyway
as whenever the UI thread is sleeping, your whole UI is frozen, preventing
the user from moving, resizing or using it.

.



Relevant Pages

  • Re: MessageBox.Show and program behaviour
    ... Your code is just an infinite loop where you fill your APListView, ... sleep then fill your APListView again, ... message queue messages and to paint your APListView. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Code executing too fast -- causes errors
    ... is also a queue of messages waiting to be processed. ... As you say, sleep suspends execution for a given duration, then resumes ... The key difference between the two approaches is that DoEvents will permit ... Private Sub CommandButton1_Click ...
    (microsoft.public.word.vba.beginners)
  • [PATCH 07/28] SLOW_WORK: Allow a requeueable work item to sleep till the thread is needed
    ... Add a function to allow a requeueable work item to sleep till the thread ... processing it is needed by the slow-work facility to perform other work. ... this only works if there is something on the queue for it to queue ... This function will then sleep until either the item's event occurs or another ...
    (Linux-Kernel)
  • plz read my paper on wait queues and give me feedback
    ... The desired behavior is to put the process to sleep and wake ... Each entry on the queue describes some process that is sleeping ... Here is how to use the macros: ...
    (comp.os.linux.development.system)
  • Re: How to wait for multiple threads simultaneously?
    ... A 'condition variable' is the userland-equivalent of a sleep channel ... wait queue to be not worth the effort. ... It simply requires that the lock function not ... because a 'POSIX spin lock' would not ...
    (comp.os.linux.development.apps)

Loading