processor time

  • Thread starter Thread starter andreas
  • Start date Start date
A

andreas

Hi,
I have a calculation program in vb.net who is running for let us say for
more than a hour.
When I will do meanwhile something els in a office program I see that my
calculation program takes a great part (maybe 80% or more) of the processor
time and I want that it is for both 50% when the office program is using
the processor.
Is this normal and can I do somthing in the code of my calculation program
or is this simple impossible.
Thanks for any response.
 
I have a calculation program in vb.net who is running for let us say for
more than a hour.
When I will do meanwhile something els in a office program I see that my
calculation program takes a great part (maybe 80% or more) of the processor
time and I want that it is for both 50% when the office program is using
the processor.
Is this normal and can I do somthing in the code of my calculation program
or is this simple impossible.
Thanks for any response.

For the thread(s) that do the calculating, set
thread.Priority = Threading.ThreadPriority.BelowNormal
Your calculation will relinquish the cpu to other processes (eg office) and
their threads whenever the others make cpu demands. When other processes are
idle, your calculation will use 100% cpu.
 
thanks!

AMercer said:
For the thread(s) that do the calculating, set
thread.Priority = Threading.ThreadPriority.BelowNormal
Your calculation will relinquish the cpu to other processes (eg office)
and
their threads whenever the others make cpu demands. When other processes
are
idle, your calculation will use 100% cpu.
 
Hello AMercer,

Adjusting thread priorities is NOT a good idea if you can avoid it. I'm
thinking about Office and I can't conceive of a sinple application in that
suite that would require 50% of the processor. Word sits idle most of the
time.. so does Excel.. Outlook may consume a tiny bit more but for the most
part it too is idle..

-Boo
 
Adjusting thread priorities is NOT a good idea if you can avoid it. I'm
thinking about Office and I can't conceive of a sinple application in that
suite that would require 50% of the processor. Word sits idle most of the
time.. so does Excel.. Outlook may consume a tiny bit more but for the most
part it too is idle..

If one wants decent response from another app, office or otherwise, lowering
the priority of a cpu bound worker is just about perfect. In every version
of windows that I have used, a cpu bound thread adversely affects the
responsiveness of other interactive apps.
 
I have set the following commands in my program and it started obviously
well :

Dim tr As New Thread(AddressOf HaalUitverkorenen)

tr.Priority = Threading.ThreadPriority.BelowNormal

tr.Start()

HaalUitverkorenen()

If tr.ThreadState = Threading.ThreadState.Running Then

tr.Abort()

End If


But I recieved quickly a exception because I put a string in a textbox
during the excecution of the sub HaalUitverkorenen :
the exception was telling :

Cross-thread operation not valid: Control 'TextBox1' accessed from a thread
other than the thread it was created on.

the textbox was placed in the beginning of the design on my form

what can I do?
 
I have set the following commands in my program and it started obviously
well :

Dim tr As New Thread(AddressOf HaalUitverkorenen)
tr.Priority = Threading.ThreadPriority.BelowNormal
tr.Start()
HaalUitverkorenen()
If tr.ThreadState = Threading.ThreadState.Running Then
tr.Abort()
End If

But I recieved quickly a exception because I put a string in a textbox
during the excecution of the sub HaalUitverkorenen :
the exception was telling :

Cross-thread operation not valid: Control 'TextBox1' accessed from a thread
other than the thread it was created on.

the textbox was placed in the beginning of the design on my form

what can I do?

I see two things that look like problems. First, you do tr.Start() on a
thread that will run at function HaalUitverkorenen(), and then your main
thread also calls functionHaalUitverkorenen(). This looks to me like you
will execute HaalUitverkorenen() twice, once on the new thread and once on
the main thread. In the code fragment, I think all you need is
Dim tr As New Thread(AddressOf HaalUitverkorenen)
tr.Priority = Threading.ThreadPriority.BelowNormal
tr.Start()

Second, there is a issue with windows where code that operates on some
controls has to execute on the same thread that the control execute on. So,
once you run HaalUitverkorenen() on its own thread, it cannot manipulate
forms and controls directly. There is a variety of written material on how
to solve this problem in the .net help documentation under the topic of
Invoke. The general idea is that your HaalUitverkorenen() thread can be made
to execute gui code on the gui main thread by appropriate function calls.
 
Yes, I had seen the first problem and the second I will try your
propositiion.
But should it be not better to give the whole program at once a lower
priority so tha it runs for 100% if there are no other programs and for
let's say 10% if other programs have to use the processor.
I don't know if this is possible and if it is, what is the solution
(commands) for this?
Thanks for any response
 
But should it be not better to give the whole program at once a lower
priority so tha it runs for 100% if there are no other programs and for
let's say 10% if other programs have to use the processor.
I don't know if this is possible and if it is, what is the solution
(commands) for this?

There is no way to guarantee 10% (or about 10%) cpu demand. Ready to run
threads at higher priority win over threads at lower prioirty, and threads of
equal priority share cpu equally. That is not a complete description of what
windows does, but it is the way you should view it.

I think it is better for the gui thread of your program to run at ordinary
priority and the cpu bound calculation thread to run at BelowNormal priority.
In this way, the calculation thread will use whatever cpu is available, and
your app's gui will be just as responsive as any other app.
 
Back
Top