Hello!!!
I have developed and automation executable to druve Excel and I'm poretty happy with it apart from the fact that it consumes 100% of the CPU while it's running - even when the app should really be idling.
The problem is caused by this piece of code
while (close == false)
System.Windows.Forms.Application.DoEvents();
I got this pattern from my VSTO book ( )and it's abviously going to cause the CPU hogging that I'm experiencing.
Where can I find a better pattern for automation executables
TIA,
Doug

Automation executable consumes 100% CPU
LLam
What VSTO book are you using
Thanks!
Mike Hernandez
Community Program Manager
VSTO Team
EW
by Eric Carter, Eric Lippert
Sampy MSFT
For the bad programming I referred to the book ;-) I learned not to trust the correctness, usefullness etc.. for each code (microsoft) sample.
A more elegant solution might be to hook into the Close event or Exit event but if the COM interface is not exposing this or the VSTO assemblies have not copied those then you're stuck with this...
VSTO in its current form (2005) is not a full blown maneged automation api. We have to wait for that for VSTA and Office 12.
Rene
Tilfried Weissenberger
Rene,
Agreed on the bad programming habit....
I implemented your suggestion and it works nicely - Thanx. But I still feel that the basic approach is kind of inelegant and that there must be a recommended way to support this automation executable pattern - it is part of VSTO after all.....
Doug
s0r3n
Just give the OS a little more time in your so called tight loop
while (close == false)
{
System.Windows.Forms.Application.DoEvents();
System.Threading.Thread.Sleep(100); // will pause the thread for 100 milliseconds
}
This will reduce the load on your CPU
(And indeed a bad book... might be a great source for VSTO, but it is advocating bad programming habits)
Rene
The ZMan
Rene,
OK - Thanx for the help. This works pretty well and I'll wait for Office 12 to salve my conscience.....:)
Doug
a_subscriber