FYI: Do not use Application.DoEvents() --- it's EVIL

427 views
Skip to first unread message

Koczka Tamás

unread,
Jul 28, 2010, 5:47:48 PM7/28/10
to exce...@googlegroups.com
Hi everyone!

I debugged all day and I figured out that the Application.DoEvents()
can cause AccessViolation exception (it means ~ memory corruption) and
crash Excel.

It usually happens infrequently and randomly, so it was hard to catch it.

I read after, and I found out that this is a reentrancy problem
(facepalm, of course it is):
http://www.techtalkz.com/c-c-sharp/83924-application-doevents.html

So if you don't want to suffer from unexpected side-effects then the
best is not to use DoEvents!

My program uses a Form for logging and for the program's settings and
I thought it would be a good idea to refresh it while excel is doing
the calculation, but my one-line implementation (calling DoEvents) was
the worst idea I had...

Sorry if my letter had no new information for you and thank you Govert
for this great software, we love it btw :)

Thanks,
Tamás Koczka

Ps: sorry for my English

Chris Spicer

unread,
Jul 30, 2010, 5:19:50 AM7/30/10
to Excel-Dna
Hi Tamas,

Thanks for this. If I read your post correctly, you are saying that
you called Application.DoEvents in the middle of a user defined
function?

I wouldn't feel too bad - I think we've all fallen into this trap at
some point or another. As a rule, Excel calculations and Excel 'macro/
object' calls are to be kept separate!

All the best,

Chris
Reply all
Reply to author
Forward
0 new messages