Click here to Skip to main content
15,901,205 members
Home / Discussions / C#
   

C#

 
GeneralRe: Web Services Applications Pin
electriac11-Dec-09 14:34
electriac11-Dec-09 14:34 
GeneralRe: Web Services Applications Pin
Luc Pattyn11-Dec-09 14:49
sitebuilderLuc Pattyn11-Dec-09 14:49 
QuestionError: cannot convert from 'ref Scripting.Dictionary [c:\...\Interop.Scripting.dll]' to 'ref Scripting.Dictionary []' Pin
Wes Jones11-Dec-09 11:58
Wes Jones11-Dec-09 11:58 
AnswerRe: Error: cannot convert from 'ref Scripting.Dictionary [c:\...\Interop.Scripting.dll]' to 'ref Scripting.Dictionary []' Pin
Abhinav S11-Dec-09 22:45
Abhinav S11-Dec-09 22:45 
QuestionVisual Studio 2008 Windows Service - CPU process usage [modified] Pin
Tomb42111-Dec-09 10:56
Tomb42111-Dec-09 10:56 
AnswerRe: Visual Studio 2008 Windows Service - CPU process usage Pin
Luc Pattyn11-Dec-09 11:06
sitebuilderLuc Pattyn11-Dec-09 11:06 
GeneralRe: Visual Studio 2008 Windows Service - CPU process usage Pin
Tomb42112-Dec-09 1:53
Tomb42112-Dec-09 1:53 
AnswerRe: Visual Studio 2008 Windows Service - CPU process usage Pin
Luc Pattyn12-Dec-09 2:28
sitebuilderLuc Pattyn12-Dec-09 2:28 
Thanks for PRE tags.
I'm replying here as this allows me to still see your code while I type.

IMO the problem is this: AppNameService contains one big loop (do ... while bolContinue), which contains some conditional tests. In one path a blocking method (WaitForExit) is called; in all other execution paths (when bolCompareValue is false or when bolFilesToProcess is false), the code never becomes idle, hence uses all available cycles to hurry up and start the next loop iteration.

There are a couple of ways to fix this:
1. the easy one: when nothing needs to be done in an iteration, call Thread.Sleep(100) to relinquisg the CPU for 100 msec, or whatever number that looks fine, but not below 10, as that is about equal to the system's tick resolution (see my Timers article).
2. the more economical one: if possible, make everything event-driven, i.e. don't poll (=check for certain conditions) at all, just tell the party responsible for those conditions to send you a signal. This isn't always possible.

Some additional comments:
1. there is no need to write if (booleanFlag==true) ..., a simple if (booleanFlag) ... behaves identically in C#.
2. in your try block, you are logging the Exception.Message but ignoring all the extra information that may be present in the Exception, and only gets visible by looking at its remaining properties (or easier: by looking at Exception.ToString(); I recommend keeping a log file with all the ToString() results, assuming they would be too much to put into the existing eventLog)
3. I don't like explicit GC.Collect() calls; maybe it is OK or even good in a service, I would certainly ban them from interactive programs.


Smile | :)

Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]

I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


GeneralRe: Visual Studio 2008 Windows Service - CPU process usage Pin
Tomb42112-Dec-09 4:14
Tomb42112-Dec-09 4:14 
GeneralRe: Visual Studio 2008 Windows Service - CPU process usage Pin
Tomb42114-Dec-09 2:31
Tomb42114-Dec-09 2:31 
QuestionListView in WPF Pin
Antonio JVS11-Dec-09 8:28
Antonio JVS11-Dec-09 8:28 
QuestionLoader Lock was detected [modified] Pin
Xelalem11-Dec-09 7:58
Xelalem11-Dec-09 7:58 
AnswerRe: Loader Lock was detected Pin
Saksida Bojan11-Dec-09 8:56
Saksida Bojan11-Dec-09 8:56 
QuestionInfo about casting Pin
Saksida Bojan11-Dec-09 7:55
Saksida Bojan11-Dec-09 7:55 
AnswerRe: Info about casting Pin
Andrew Rissing11-Dec-09 8:00
Andrew Rissing11-Dec-09 8:00 
GeneralRe: Info about casting Pin
Andrew Rissing11-Dec-09 8:03
Andrew Rissing11-Dec-09 8:03 
GeneralRe: Info about casting Pin
Saksida Bojan11-Dec-09 8:43
Saksida Bojan11-Dec-09 8:43 
GeneralRe: Info about casting Pin
harold aptroot11-Dec-09 9:03
harold aptroot11-Dec-09 9:03 
QuestionHow do I attach event handlers to a late-bound object (C#)? Pin
Hawks Talon11-Dec-09 6:52
Hawks Talon11-Dec-09 6:52 
AnswerRe: How do I attach event handlers to a late-bound object (C#)? Pin
Saksida Bojan11-Dec-09 7:03
Saksida Bojan11-Dec-09 7:03 
GeneralRe: How do I attach event handlers to a late-bound object (C#)? Pin
Hawks Talon11-Dec-09 7:35
Hawks Talon11-Dec-09 7:35 
QuestionWMI 'Invalid Method Parameter(s)' JoinDomainOrWorkGroup Pin
Jacob Dixon11-Dec-09 5:52
Jacob Dixon11-Dec-09 5:52 
AnswerRe: WMI 'Invalid Method Parameter(s)' JoinDomainOrWorkGroup Pin
Luc Pattyn11-Dec-09 6:04
sitebuilderLuc Pattyn11-Dec-09 6:04 
GeneralRe: WMI 'Invalid Method Parameter(s)' JoinDomainOrWorkGroup Pin
Jacob Dixon11-Dec-09 6:14
Jacob Dixon11-Dec-09 6:14 
AnswerRe: WMI 'Invalid Method Parameter(s)' JoinDomainOrWorkGroup Pin
Saksida Bojan11-Dec-09 6:52
Saksida Bojan11-Dec-09 6:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.