G
Guest
If the culprit is the events perhaps you should rethink your design... and
use a shared or global variable to communicate state. The UI thread would
periodically check the status rather then the worker thread informing the UI
via events.
use a shared or global variable to communicate state. The UI thread would
periodically check the status rather then the worker thread informing the UI
via events.
Charles Law said:It's random in the sense that it doesn't always happen during the same
operation, and sometimes it doesn't happen at all.
The worker thread, repeatedly, does things like this:
DoTask1
DoTask2
DoTask7
DoTask2
All these tasks have to be performed within a couple of seconds. Nominally,
task1 takes 60 ms, task 2 takes 10 ms, and task 7 takes 550 ms, say.
The expectation, therefore, is that the whole process is over in less than 1
second. Sometimes, though, task 1 takes 2.5 seconds, for no reason I can
discern. Therefore, the entire sequence takes longer than the allowed time,
and the process fails. That said, it is not always task 1 that takes the
excess time; it could be task 2, or task 7, or task 43.
Each of these tasks will send and receive data on a serial port. I have
timed the serial comms carefully, and it consistently takes no more than 25
ms to send and receive data. Thus, I conclude that the time is spent
elsewhere.
Before each task is started, an event is raised to inform the UI that the
task is starting. The UI updates a rich text control using BeginInvoke. I am
wondering if these requests to update the UI pile up, for example, and
eventually get flushed, holding up the worker thread. The screen appears to
update steadily, but by definition the screen updates will not be
synchronised to the update requests, so some of them might result from the
clearing of a backlog.
When the UI displays the task being performed, I display the absolute time
and the delta based on a high res counter.
I will have a look at the performance counter you mention.
Charles
Niki Estner said:Charles Law said:Hi Niki
Thanks for the response. I currently display the absolute and elapsed
times using a high res timer, which is how I can see the difference
between the expected and actual timings. I guess I could add more time
displays, but it would generate a lot of output, and whilst it might tell
me when and where in my code the excess time is taken, I am not sure it
will necessarily tell me why. I don't think it is my code (they all say
that), because it is so random.
Is it really random? How can you know without knowing where it happens? I
thought all you knew was that it doesn't happen every time?
Did you analyze the time delta's? How are they distributed? Is there a
normal distribution around 300 ms plus some peaks at 2,5 s? If so, did you
check where those peaks are? (I always dump output like that to a text
file and use Excel to analyze it later)
- Monitor the .NET performance counters. Is there maybe some correlation
to GC collection or some other runtime event?
How can I tell when garbage collection occurs?
I have a German windows version, so I can't tell you the exact name of the
performance counter, should be something like "Number of GCs" in the ".NET
Memory" performance counters section. It increases by one with each GC
collection. Use perfmon to record it while you test your app.
- Which GC do you use?
How many are there? I thought there was just the one, built-in to the
framework.
MSDN Quote: "The CLR has two different GCs: Workstation (mscorwks.dll) and
Server (mscorsvr.dll). When running in Workstation mode, latency is more
of a concern than space or efficiency. A server with multiple processors
and clients connected over a network can afford some latency, but
throughput is now a top priority. Rather than shoehorn both of these
scenarios into a single GC scheme, Microsoft has included two garbage
collectors that are tailored to each situation."
[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/dotnetperftechs.asp]
You'll have to host the runtime to choose between the two, but I think the
workstation version is the better choice for you anyway.
Niki