Multithreading causes slow down

My application is multithreaded, at most cases it runs up to 3 extra threads at the same time.
Some of my software users have issues with getting their pc slowed down alot.
They said the application is using up to 100% system usage, i cant find howto solve this problem by myself.
The first thread which is taking alot usage is doing the following:
calls to System.Diagnostics.Process.GetProcessesByName() to check if a specific process is running and several ReadProcessMemory calls.
I already tried Thread.Priority = lowest but it doesnt helps at all.
korpiklaaniAsked:
Who is Participating?
 
Jens FiedererConnect With a Mentor Test Developer/ValidatorCommented:
So your sleep has a large effect....I would guess it is a lot higher than 1% for a fraction of a second, but then drops to 0% while it is sleeping.

To reduce usage, there are two possibilities:
1) run operation less often (i.e., increase sleep)
2) make operation more efficient (for example, use an alternative to GetProcessesByName (or ReadProcessMemory, if that is where your problem is, although there have been some complaints about slowness in the earlier, see http://74.125.113.132/search?q=cache:BA4VlKChk0YJ:www.itags.org/dotnet/1169208/+GetProcessesByName&cd=26&hl=en&ct=clnk&gl=us )
0
 
Jens FiedererTest Developer/ValidatorCommented:
How often do you do System.Diagnostics.Process.GetProcessesByName()?  

Just once, or continuously?  If continuously, you might want to sleep a bit between calls.
0
 
korpiklaaniAuthor Commented:
i have a 500ms sleep at the end of the thread
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Jens FiedererTest Developer/ValidatorCommented:
And the thread does not contain a loop?
0
 
korpiklaaniAuthor Commented:
the thread loops using a while loop
0
 
Jens FiedererTest Developer/ValidatorCommented:
Have you tried putting your "sleep" INSIDE the while loop?
0
 
korpiklaaniAuthor Commented:
yes of course, it is inside the while loop
0
 
Jens FiedererTest Developer/ValidatorCommented:
OK, you said at the "end of the thread".

Are there any other loops in the thread that could be busy-waiting?
0
 
korpiklaaniAuthor Commented:
no other loops, i found when i put the sleep at the end on 5000ms it works way better but is that the only solution?
0
 
Jens FiedererTest Developer/ValidatorCommented:
500ms sleeps should be enough to avoid 100% usage...how about the other threads?

0
 
korpiklaaniAuthor Commented:
they are not running at that time, later they just get started.
well but even 50% is too much with 500ms
0
 
Jens FiedererTest Developer/ValidatorCommented:
How much does it go to with 5000ms?
0
 
korpiklaaniAuthor Commented:
0 - 1%
0
 
korpiklaaniAuthor Commented:
i guess that is the only way
0
All Courses

From novice to tech pro — start learning today.