|
if memory serves me correctly Task Class[^] and Parallel.ForEach[^] are optimised to handle the cores of a processor better than Threading class or threadpool .
But you haven't really given much information to help us give you a better answer.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
One logical processor can run one thread at a time - and this includes all the of system threads, as well as all the application threads in the machine - not just yours. So at any one time, four threads can be running at the same time, and one or more of these may be one of your 25. The system is at liberty to start threads on any processor available to it at the time it wants to switch threads - either because a thread has paused itself, ot run out of time slice and must wait to give other threads a chance.
You can't force a thread onto an processor, or even force a thread to run without interruption from beginning to end. So all 25 thread could run on the same processor, one after another, or they could be spread around - you have no influence over that, and cannot even tell which processor you are running on: or even if it was the same processor a microsecond ago!
Do be aware that if you start a number of threads to speed things up, you may infact slow things down due to locking and thread switching overheads - particularly if there aren't enough physical processors to run them all at the same time.
This message is manufactured from fully recyclable noughts and ones. To recycle this message, please separate into two tidy piles, and take them to your nearest local recycling centre.
Please note that in some areas noughts are always replaced with zeros by law, and many facilities cannot recycle zeroes - in this case, please bury them in your back garden and water frequently.
|
|
|
|
|
Quote: You can't force a thread onto an processor,
I'm not claiming any expertise on this subject and have no idea why one would wish to do this.
But couldn't you iterate through Process.GetCurrentProcess.Threads seeking the ProcessThread which has the ID equal to the ID returned from the API function GetCurrentThreadId (called on the thread in question).
Once you have the needed ProcessThread, you could set its processor affinity[^] property.
|
|
|
|
|
TnTinMn wrote: I'm not claiming any expertise on this subject and have no idea why one would wish to do this. Attempting to improve performance, I'd guess.
Still, Windows will halt the thread from time to time, and while one can set an affinity, one can not claim a specific core.
that's a good thing
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
I'm pretty sure no one is going to open that link.
|
|
|
|
|
And nobody is going to fix your code for you.
Why should we (doing this for free) do your job for you (YOU get paid for it)?? Do you see a problem with this??
|
|
|
|
|
hi every body
i wish i could find somebody help
i want my window to be shown slowly from left corner up and then go down when a button clicked and after a atimer interval the form shown again
this the code i tries but the form doesnt shown again
<pre>namespace moving_form
{
public partial class Form1 : Form
{
bool flag = true;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Left = 0;
this.Top = Screen.PrimaryScreen.Bounds.Height + this.Height - 30;
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{ flag = true;
if (this.Top >= Screen.PrimaryScreen.Bounds.Height - this.Height - 30)
this.Top = this.Top - 10;
}
private void button1_Click(object sender, EventArgs e)
{
timer2.Enabled = true;
}
private void timer2_Tick(object sender, EventArgs e)
{
flag = false;
if (this.Top > Screen.PrimaryScreen.Bounds.Height)
{
return;
}
else
{
this.Top = this.Top + 10;
flag = true;
}
}
}
}
thanx again
|
|
|
|
|
Maybe you didn't start your timer?
|
|
|
|
|
no,
unfotunately its enabled and sterted
|
|
|
|
|
Edit :
I changed your code but yeah it's messy.
My advice,
* Reduce timer usage
* Stop your timer when you don't need them (not keep returning)
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
timer3.Interval = 1000;
}
bool flag = true;
int delay = 0;
private void Form1_Load(object sender, EventArgs e)
{
this.Left = 0;
this.Top = Screen.PrimaryScreen.Bounds.Height + this.Height - 30;
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
flag = true;
if (this.Top >= Screen.PrimaryScreen.Bounds.Height - this.Height - 30)
{
this.Top = this.Top - 10;
}
else
{
timer1.Enabled = false;
}
}
private void timer2_Tick(object sender, EventArgs e)
{
flag = false;
if (this.Top > Screen.PrimaryScreen.Bounds.Height)
{
timer2.Enabled = false;
timer3.Enabled = true;
return;
}
else
{
this.Top = this.Top + 10;
flag = true;
}
}
private void button1_Click(object sender, EventArgs e)
{
timer2.Enabled = true;
}
private void timer3_Tick(object sender, EventArgs e)
{
if (this.delay >= 5)
{
this.delay = 0;
timer1.Enabled = true;
timer3.Enabled = false;
}
else
{
this.delay += 1;
}
}
}
modified 16-Sep-13 0:37am.
|
|
|
|
|
thaks alot the code ig going down an back up when button pressed
but there is one more thing
how can i make the form come up again after two minutes for example?
i have try adding interval time but no use
thanx again
waiting
|
|
|
|
|
what is your problem with this code?
|
|
|
|
|
it doesnt do the movement up-down an down-up of the form in the corner of the screen
|
|
|
|
|
you must set timer.enabled= true
timer.interval =1000 milissecond
and
in timer event timer
copy your code for move
for example
buton1.left=buton1.left+100;(for x axis)
buton1.top=buton1.top+200;(for y axis)
|
|
|
|
|
i didi that still no use
|
|
|
|
|
I can see several problems:
- are the timers started when the button is pressed? What is the interval?
- It's possible that you need to send a redraw command on each tick (like update or invalidate or something)
- I'm confused the compiler doesn't complain about the flag variable. It's accessed across threads.
- why two timers? I believe 1 timer should be able to do the trick ?
the simplest way to go on about this IMHO is:
- 1 timer.
- 1 static boolean (true when button pressed, false when movement was done)
- 1 static counter that counts each passing of the the timer_tick handler.
- 1 static (final) stopvalue for when the work should stop.
in timer_tick you then check counter vs stopvalue (= amount of time), set the flag on false and reset the form, in an if(flag==true) block you can then move the form.
this is quick thinking, you can go into the details from there.
hope this helps...
|
|
|
|
|
thanks alot for your hints
i will try them
my problem is in how make the form come up again after its hidden in the corner after 2 minutes ?
|
|
|
|
|
if the goal is to hide the form you should use the Visible property (see here[^])
else you just reset the location of the form. You could keep the initial location in a Point variable and reset it to that when you reset the form.
|
|
|
|
|
the goal is not hiding the form
i want to move it down and after an interval make it move up again as its shown first
if i hide data order will be lost " bindingsource.movenext " so i just wan to delay its appearance wth the samem data >>> by move it up and down ,,up and down
how can i move it up again after passed time ?
hope u got me
thank you all again
i appreciate
|
|
|
|
|
I answered it already.
To move the form you need to change the location property. Possibly you'll need to force a redraw by calling invalidate or refresh or update or something.
If you want to set it back after an amount of time you need to store the original location before moving.
Moving is with X-Y coordinates (per pixel) where X is moving from left to right and Y from top to bottom.
So on a 1024x768 screen the top-left corner is 0,0 and the bottom-right corner 1024,768.
This should provide you with enough information to get you going.
|
|
|
|
|
I've put the comment on where to change the delay.
And I changed the interval to 1000 so the tick event execute every 1 second.
So you don't have to change the interval anymore.
|
|
|
|
|
yessssssss that wat i want
thanks alot midnight
thanks all
|
|
|
|
|
the form is comimg up and then come back down when click a button
what if i want the for to come down again after its shown for 1 minutes for example
have i add a timer test the
i will be gratefull
|
|
|
|
|
yes, you can create a timer that will start when the form is shown or change your code to make it better, less timer.
|
|
|
|