Re: Time Critical Process in .NET

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 03/17/05


Date: Thu, 17 Mar 2005 12:38:49 -0600

Charles,
> Is it possible to suspend garbage collection for critical sections?
Unfortunately, or is it fortunately. No you cannot.

Jay

"Charles Law" <blank@nowhere.com> wrote in message
news:uz$7SBoKFHA.3916@TK2MSFTNGP14.phx.gbl...
> Hi Jay
>
> A lot of good information, as usual. I shall mull it over and try some of
> this out.
>
>> Can you use CLR profiler or custom performance counters to identify that
>> a Garbage Collection is not occurring during this "critical" process? Can
>> you redesign the critical process to minimize garbage collections if this
>> is the problem?
>
> Is it possible to suspend garbage collection for critical sections?
>
>> Are you certain that windows did not suspend your program in favor of
>> allowing another program to run?
>
> There is nothing obviously getting control; very little else is running.
> The m/c is not networked, and apart from Norton Antivirus - which is
> disabled - there is nothing much else.
>
>> Have you tried using Thread.Priority and/or Process.PriorityClass &
>> Process.PriorityBoostEnabled so Windows will favor your thread/process?
>
> I haven't, but I will take a look.
>
> Cheers.
>
> Charles
>
>
> "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
> news:%23PimRtkKFHA.2640@TK2MSFTNGP09.phx.gbl...
>> Charles,
>> This sounds like the ideal use of multiple threads!
>>
>> I'm not sure what Cor was smoking when he responded :-|
>>
>> However due to the nature of .NET (non-deterministic garbage collection)
>> & Windows preemptive scheduling; "real-time" critical processes are hard
>> to achieve.
>>
>> Can you use CLR profiler or custom performance counters to identify that
>> a Garbage Collection is not occurring during this "critical" process? Can
>> you redesign the critical process to minimize garbage collections if this
>> is the problem?
>>
>> Are you certain that windows did not suspend your program in favor of
>> allowing another program to run?
>>
>> Have you tried using Thread.Priority and/or Process.PriorityClass &
>> Process.PriorityBoostEnabled so Windows will favor your thread/process?
>>
>> WARNING: I would use Process.PriorityClass & Process.PriorityBoostEnabled
>> with extreme caution!
>>
>> Info on the CLR Profiler:
>> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenethowto13.asp
>>
>> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/highperfmanagedapps.asp
>>
>> Hope this helps
>> Jay
>>
>> "Charles Law" <blank@nowhere.com> wrote in message
>> news:uuG%231YhKFHA.508@TK2MSFTNGP12.phx.gbl...
>>> Hi guys
>>>
>>> I have a time critical process, running on a worker thread. By "time
>>> critical", I mean that certain parts of the process must be completed in
>>> a specific time frame. The time when the process starts is not
>>> especially important, but it must be complete within a small number of
>>> seconds.
>>>
>>> The operations I am performing do not take a long time (hundreds of
>>> milliseconds), but as each part of the process is complete, my worker
>>> thread raises an event that is handled by the UI thread, to update a
>>> rich text control with details of the completed operation. I am using a
>>> rich text box so that when a failure occurs I can colour the message
>>> red.
>>>
>>> The problem I have is that sometimes, for no apparent reason, a step in
>>> my process takes an inordinate amount of time, e.g 2.5 seconds instead
>>> of perhaps 300 ms. When this happens, the complete process overruns my
>>> time frame, and it has to be repeated. When I repeat the process there
>>> is every chance that it completes in a realistic time, and all is well.
>>> If I stop outputting to the screen, I do not get the problem.
>>>
>>> When updating the screen on the UI thread, I use BeginInvoke, to marshal
>>> the operation to the correct thread, and so as not to hold up the worker
>>> thread, but this does not seem to help.
>>>
>>> I realise that Windows (XP in this case) is not the ideal o/s for this
>>> type of application, but does anyone have any ideas about how I could
>>> make my application more deterministic? I am not certain what is going
>>> on in these 2.5 seconds, so it might be useful if I could find out, but
>>> I am not sure how I would do that.
>>>
>>> TIA
>>>
>>> Charles
>>>
>>>
>>
>>
>
>