vb.net - Threading.Timer application is consuming more than 50% of CPU, why? -


i have written below console application in vb.net.

my intention write application triggers every 1 minute , perform task. but

when run application consuming 50% of cpu.

how can make consume less cpu?

am calling timer in right place (in main method)?

later make windows service same task , install on server.

how can make application consume less cpu?

module module1      dim inputpath string = "c:\input"     dim outputpath string = "c:\output"     dim folder directory      sub main()         dim tmr timer = new timer(new timercallback(addressof upload), nothing, 1000, 60000)         while not tmr nothing         end while      end sub      public sub upload(byval o object)         dim sr streamreader         dim constr1 string = "data source=tns name;user id=xx; password=xx;"         'look pending requests in rqst_tbl         dim cnn1 new oracleconnection(constr1)         dim datreader oracledatareader         dim cmd1 new oraclecommand         cnn1.open()         .....         .....     end sub  end module 

thank you..

i'm guessing have 2 cpus? infinite while loop consuming 100% of 1 cpu; leaving 50% total cpu consumption.

from of code - loop unneeded. timer class going call upload() method when complete.

remove while loop...

while not tmr nothing  end while 

and use console.readline keep application closing.

alternatively stick thread.sleep() call inside while loop if loop.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -