DoEvents not doing any events 
Author Message
 DoEvents not doing any events

Hi there,

    I have placed Doevents at the end of intensive loops within a class
library that I have written.  Sometimes I get the following error message,

    Handler not initialized

    The error points to the doEvents, I can get rid of the error by simply
removing the line, and no errors seem to show up in my code.  But what is
actually happening here?  I thought it was supposed to make the current
thread yeild to the operator if there are any pending events, this
SHOUDLN'|T crash! Should it??  Maybe I have got it wrong, but it is nice to
prevent the application from freezing during loops.  Any ideas, thanks in
advance.

Nick.



Thu, 01 Dec 2005 04:23:47 GMT  
 DoEvents not doing any events
Hello,


Quote:
> I have placed Doevents at the end of intensive loops within
> a class library that I have written.  Sometimes I get the following
> error message,

Why don't you start the operation in a separate thread?

DoEvents is useful in Windows Forms applications only.

Regards,
Herfried K. Wagner
--
MVP VB Classic, VB .NET
http://www.mvps.org/dotnet



Thu, 01 Dec 2005 20:40:49 GMT  
 DoEvents not doing any events
Nak,
As Herfried suggested.

How and where are you starting this routine?

If you simply want the current thread to yield, you can call
System.Threading.Thread.Sleep(0).

If you want your main thread to handle any pending events you can use
System.Windows.Forms.Application.DoEvents(), in addition to handling any
pending events, this will also yield to other threads.

I would expect DoEvents on a non-window (not the main) thread to behave
badly.

Hope this helps
Jay


Quote:
> Hi there,

>     I have placed Doevents at the end of intensive loops within a class
> library that I have written.  Sometimes I get the following error message,

>     Handler not initialized

>     The error points to the doEvents, I can get rid of the error by simply
> removing the line, and no errors seem to show up in my code.  But what is
> actually happening here?  I thought it was supposed to make the current
> thread yeild to the operator if there are any pending events, this
> SHOUDLN'|T crash! Should it??  Maybe I have got it wrong, but it is nice
to
> prevent the application from freezing during loops.  Any ideas, thanks in
> advance.

> Nick.



Fri, 02 Dec 2005 01:48:46 GMT  
 DoEvents not doing any events
Thanks Herfried and Jay,

    I didn't actually think that it wouldn't work in a non windows forms
application.  I'm trying to use the DoEvents in a thumbnail control that I
have made.  I would love to make the viewing part in another thread but this
seems very difficult to impliment, I got half way and got rather confused by
the idea.  That would make great sence to have it like that though, the
control sets up in one thread by positioning thumbnail placeholders etc, and
one thread places the thumbnails inside of the placeholders.  I'll try the
sleep method as you have suggested, I hadn't thought to use that one before
as I thought it froze the application, but you have suggested sleeping for 0
ms, which sounds a bit strange.  I'll {*filter*} off and take another look at
multithreading it.  Thanks loads :-)

Nick.



Quote:
> Nak,
> As Herfried suggested.

> How and where are you starting this routine?

> If you simply want the current thread to yield, you can call
> System.Threading.Thread.Sleep(0).

> If you want your main thread to handle any pending events you can use
> System.Windows.Forms.Application.DoEvents(), in addition to handling any
> pending events, this will also yield to other threads.

> I would expect DoEvents on a non-window (not the main) thread to behave
> badly.

> Hope this helps
> Jay



> > Hi there,

> >     I have placed Doevents at the end of intensive loops within a class
> > library that I have written.  Sometimes I get the following error
message,

> >     Handler not initialized

> >     The error points to the doEvents, I can get rid of the error by
simply
> > removing the line, and no errors seem to show up in my code.  But what
is
> > actually happening here?  I thought it was supposed to make the current
> > thread yeild to the operator if there are any pending events, this
> > SHOUDLN'|T crash! Should it??  Maybe I have got it wrong, but it is nice
> to
> > prevent the application from freezing during loops.  Any ideas, thanks
in
> > advance.

> > Nick.



Fri, 02 Dec 2005 03:17:27 GMT  
 DoEvents not doing any events
Hi,

I tried using the thread.sleep call over Do Events but couldn't
achieve the same result. I have an app which displays an alert -
Flash Screen 1
Beep
Flash Reversed Screen 1
repeat

I need the doevents to allow the different screens to show - with Do
Events, it works, but with thread.sleep it doesn't.

Regards,

David.


Quote:
> Nak,
> As Herfried suggested.

> How and where are you starting this routine?

> If you simply want the current thread to yield, you can call
> System.Threading.Thread.Sleep(0).

> If you want your main thread to handle any pending events you can use
> System.Windows.Forms.Application.DoEvents(), in addition to handling any
> pending events, this will also yield to other threads.

> I would expect DoEvents on a non-window (not the main) thread to behave
> badly.

> Hope this helps
> Jay



> > Hi there,

> >     I have placed Doevents at the end of intensive loops within a class
> > library that I have written.  Sometimes I get the following error message,

> >     Handler not initialized

> >     The error points to the doEvents, I can get rid of the error by simply
> > removing the line, and no errors seem to show up in my code.  But what is
> > actually happening here?  I thought it was supposed to make the current
> > thread yeild to the operator if there are any pending events, this
> > SHOUDLN'|T crash! Should it??  Maybe I have got it wrong, but it is nice
>  to
> > prevent the application from freezing during loops.  Any ideas, thanks in
> > advance.

> > Nick.



Fri, 02 Dec 2005 06:49:32 GMT  
 DoEvents not doing any events
Sleep(0) tells your thread to sleep only if there are other threads waiting
to execute, and it yields only its current timeslice (i think).

-- russ


Quote:
> Thanks Herfried and Jay,

>     I didn't actually think that it wouldn't work in a non windows forms
> application.  I'm trying to use the DoEvents in a thumbnail control that I
> have made.  I would love to make the viewing part in another thread but
this
> seems very difficult to impliment, I got half way and got rather confused
by
> the idea.  That would make great sence to have it like that though, the
> control sets up in one thread by positioning thumbnail placeholders etc,
and
> one thread places the thumbnails inside of the placeholders.  I'll try the
> sleep method as you have suggested, I hadn't thought to use that one
before
> as I thought it froze the application, but you have suggested sleeping for
0
> ms, which sounds a bit strange.  I'll {*filter*} off and take another look at
> multithreading it.  Thanks loads :-)

> Nick.


message

> > Nak,
> > As Herfried suggested.

> > How and where are you starting this routine?

> > If you simply want the current thread to yield, you can call
> > System.Threading.Thread.Sleep(0).

> > If you want your main thread to handle any pending events you can use
> > System.Windows.Forms.Application.DoEvents(), in addition to handling any
> > pending events, this will also yield to other threads.

> > I would expect DoEvents on a non-window (not the main) thread to behave
> > badly.

> > Hope this helps
> > Jay



> > > Hi there,

> > >     I have placed Doevents at the end of intensive loops within a
class
> > > library that I have written.  Sometimes I get the following error
> message,

> > >     Handler not initialized

> > >     The error points to the doEvents, I can get rid of the error by
> simply
> > > removing the line, and no errors seem to show up in my code.  But what
> is
> > > actually happening here?  I thought it was supposed to make the
current
> > > thread yeild to the operator if there are any pending events, this
> > > SHOUDLN'|T crash! Should it??  Maybe I have got it wrong, but it is
nice
> > to
> > > prevent the application from freezing during loops.  Any ideas, thanks
> in
> > > advance.

> > > Nick.



Fri, 02 Dec 2005 12:53:01 GMT  
 DoEvents not doing any events
David,
Are you using multiple threads?

If you are not using multiple threads, then using thread.sleep doesn't
really make sense.

If you have a single thread, and using controls/forms, then using DoEvents
make sense.

Just be aware that all of your events will fire when you call DoEvents,
which mean that you may get a button click to start a process that is
already started.

If you want a screen to update you want DoEvents, as you need the Paint
event handled. I believe Control.Refresh will force the Paint event to be
handled immediately. Control.Refresh is basically Control.Invalidate
followed by Control.Update. Which may be safer than DoEvents, I just have
not tried Control.Refresh much...

Hope this helps
Jay


Quote:
> Hi,

> I tried using the thread.sleep call over Do Events but couldn't
> achieve the same result. I have an app which displays an alert -
> Flash Screen 1
> Beep
> Flash Reversed Screen 1
> repeat

> I need the doevents to allow the different screens to show - with Do
> Events, it works, but with thread.sleep it doesn't.

> Regards,

> David.




- Show quoted text -

Quote:
> > Nak,
> > As Herfried suggested.

> > How and where are you starting this routine?

> > If you simply want the current thread to yield, you can call
> > System.Threading.Thread.Sleep(0).

> > If you want your main thread to handle any pending events you can use
> > System.Windows.Forms.Application.DoEvents(), in addition to handling any
> > pending events, this will also yield to other threads.

> > I would expect DoEvents on a non-window (not the main) thread to behave
> > badly.

> > Hope this helps
> > Jay



> > > Hi there,

> > >     I have placed Doevents at the end of intensive loops within a
class
> > > library that I have written.  Sometimes I get the following error
message,

> > >     Handler not initialized

> > >     The error points to the doEvents, I can get rid of the error by
simply
> > > removing the line, and no errors seem to show up in my code.  But what
is
> > > actually happening here?  I thought it was supposed to make the
current
> > > thread yeild to the operator if there are any pending events, this
> > > SHOUDLN'|T crash! Should it??  Maybe I have got it wrong, but it is
nice
> >  to
> > > prevent the application from freezing during loops.  Any ideas, thanks
in
> > > advance.

> > > Nick.



Fri, 02 Dec 2005 22:21:44 GMT  
 DoEvents not doing any events

Quote:
>     I didn't actually think that it wouldn't work in a non windows forms
> application.  I'm trying to use the DoEvents in a thumbnail control that I
> have made.  I would love to make the viewing part in another thread but
this
> seems very difficult to impliment, I got half way and got rather confused
by
> the idea.  That would make great sence to have it like that though, the
> control sets up in one thread by positioning thumbnail placeholders etc,
and
> one thread places the thumbnails inside of the placeholders.  I'll try the
> sleep method as you have suggested, I hadn't thought to use that one
before
> as I thought it froze the application, but you have suggested sleeping for
0
> ms, which sounds a bit strange.  I'll {*filter*} off and take another look at
> multithreading it.  Thanks loads :-)

This is definitely something which you should do with separate Threads. If
you try it with DoEvents and Sleep, it will be VERY messy and probably never
work qutie right. Multiple threads are not *this* hard...


Fri, 02 Dec 2005 22:51:13 GMT  
 DoEvents not doing any events

Quote:
> work qutie right. Multiple threads are not *this* hard...

Yeah, techincally you are right, but in reality, it's just a complete {*filter*}
when you can have more than one bug happening at the same time, I'm not qute
sure how to abort a thread completely and then restart it again when it is
safe to do so, it didn't actually seem to work correctly.  I will have
another go and hopefully crack it, but I have more bugs going on at the
minute :-\

Nick.



Sat, 03 Dec 2005 00:34:11 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Need help with commonon dialog not doing doevents

2. MCI Control Gets Into a Tizzy - Done Events Not Being Generated

3. DoEvents when doing UpdateBatch

4. Common Dialog and Timer Events/MCI Done Event

5. DoEvents and Form_Timer event

6. Multiple Timers, Events Queue, DoEvents Don't Work

7. Timer events have their own DoEvents?

8. Doevents doesnt do events !

9. Help required with Timer Event, DoEvents, Sleep...an easy one

10. DoEvents inside COM event?

11. DoEvents inside TrueDBGrid RowColChange Event

12. HOWTO: a replacement for Doevents which does not yield to keystrokes

 

 
Powered by phpBB® Forum Software