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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Jens FiedererTest Developer/ValidatorCommented:
And the thread does not contain a loop?
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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
Jens FiedererTest 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
korpiklaaniAuthor Commented:
i guess that is the only way
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.