I downloaded the sample for this item and when running the main window and the dialog are clearly running on their own threads, however, the main window doesn't seem to be reacting to any paint requests. To repro run the project and move the dialog over the main window and the main window doesn't repaint itself. Why is this? I would like to use this technique but the ugliness of the main window not repainting itself would be too prohibitive. Thanks for any help.
CB
Clay Burch
Syncfusion Team
September 19, 2002 07:59 PM UTC
In that sample, the time consuming operation is just being simulated by an empty while loop.
while (System.Environment.TickCount - ticks < 10)
; //empty loop
This loop does not give the application a chance to handle pending window messages. If you want window messages processed during your long operation, you should call the Application.DoEvents() method during your processing loop. So, in our sample, if you add this call to the while loop, you will see the messages being processed.
while (System.Environment.TickCount - ticks < 10)
Application.DoEvents();
JA
Jon Anderson
September 19, 2002 08:08 PM UTC
Clay, thanks for your reply.
I noticed the sample used a continuously executing while loop. I know that will eat the CPU to the exclusion of other messages being processed so I switched the sample to sleep (System.Threading.Thread.Sleep) instead. My understanding is that Sleep frees the cpu to process other events as well. Am I going down the wrong path? What does DoEvents really do?
> In that sample, the time consuming operation is just being simulated by an empty while loop.
>
> while (System.Environment.TickCount - ticks < 10)
> ; //empty loop
>
>
> This loop does not give the application a chance to handle pending window messages. If you want window messages processed during your long operation, you should call the Application.DoEvents() method during your processing loop. So, in our sample, if you add this call to the while loop, you will see the messages being processed.
>
> while (System.Environment.TickCount - ticks < 10)
> Application.DoEvents();
>
JA
Jon Anderson
September 19, 2002 08:25 PM UTC
Further information... I was able to get the underlying window to repaint by placing a form1.Refresh() call in the loop.
> Clay, thanks for your reply.
>
> I noticed the sample used a continuously executing while loop. I know that will eat the CPU to the exclusion of other messages being processed so I switched the sample to sleep (System.Threading.Thread.Sleep) instead. My understanding is that Sleep frees the cpu to process other events as well. Am I going down the wrong path? What does DoEvents really do?
>
> > In that sample, the time consuming operation is just being simulated by an empty while loop.
> >
> > while (System.Environment.TickCount - ticks < 10)
> > ; //empty loop
> >
> >
> > This loop does not give the application a chance to handle pending window messages. If you want window messages processed during your long operation, you should call the Application.DoEvents() method during your processing loop. So, in our sample, if you add this call to the while loop, you will see the messages being processed.
> >
> > while (System.Environment.TickCount - ticks < 10)
> > Application.DoEvents();
> >
CB
Clay Burch
Syncfusion Team
September 19, 2002 08:39 PM UTC
I don't think Thread.Sleep will allow any of the current thread's window messages be processed as Thread.Sleep just suspends the thread processing for the requested period.
Application.DoEvents will allow window messages to be processed.
So, as far as our sample, I thnk DoEvents is a better choice. But in your application, the question is whether you want to suspend your thread's processing (with no load on the CPU during the wait), or whether you want your messages to be handled duing the processing loop. There is no way to control how long the processing of messages will take, and that might be a consideration as well.