|
Create a DateTime [^] object and use the Day and DayOfWeek properties to get the relevant values.
Veni, vidi, abiit domum
|
|
|
|
|
Try this:
DateTime mondaySept162013 = new DateTime(2013, 9, 16);
DateTime wednesday;
for (int x = 2; x > -13; x = x - 7)
{
wednesday = mondaySept162013.AddDays(x);
Console.WriteLine(wednesday.DayOfWeek + " " + wednesday.ToShortDateString());
}
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
modified 16-Sep-13 14:06pm.
|
|
|
|
|
System.DateTime t = System.DateTime.Today ;
int sub = System.DayOfWeek.Wednesday - t.DayOfWeek ;
if ( sub > 0 ) sub -= 7 ;
System.DateTime lw = t.AddDays ( sub ) ;
System.DateTime twbt = lw.AddDays ( -7 ) ;
System.DateTime nw = lw.AddDays ( 7 ) ;
System.DateTime twat = nw.AddDays ( 7 ) ;
|
|
|
|
|
PIEBALDconsult wrote: System.DateTime twat
Veni, vidi, abiit domum
|
|
|
|
|
Thank you very much!
this is the solution I have used.
Trev
|
|
|
|
|
Hello,
I had a machine with 4 logical processors(1 => physical processor, 2 => cores, 4 => logical processors). And I have implemented an application which can run with 25 threads.
Now, if i run my application(with 25 threads) on my machine(with 4 logical processors),
Are those 25 threads run on single processor or all 4 logical processors?
Can any one help me please..
Thanks,
Srini
|
|
|
|
|
Srinivas P N V wrote: Are those 25 threads run on single processor or all 4 logical processors? Whatever Windows chooses (and that may vary!) It's the OS that's responsible for scheduling threads.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
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...
|
|
|
|