Question

I have some code that spawns a few threads and invokes a Run() method on them.

What I want to do is to embed a timer into that loop which starts the threads and count how many threads have been completed.

The way I want to do that is by creating an entry in a List every time an IStuff is being ran and then count how many elements are in the list every second, and thus produce a per second result.

Not sure if I'm along the correct lines, but please suggest ways of doing that.

Was it helpful?

Solution

All you need is a variable in a shared scope, say int completionsPerSecond = 0 - and last thing your Run() method should do is increment it by 1.

Then you'd have a timer that every second, copies the value in completionsPerSecond to show you as your value, and then sets completionsPerSecond to 0.

Now every second, you'll know how many finished in the previous second.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top