ffb.boy.30
Member
- Joined
- Jan 18, 2017
- Messages
- 5
- Programming Experience
- 1-3
Hi,
I would like to make a thread loop to do calculations according time , like a PID.
For example If the loop run for 5sec and I make only a increment by one the output shoud be 5000 if my loop time is 1ms.
I've tried thread.sleep(1) in my thread loop but it is too slow, I've tried something like this
but not efficient too, it take 7.6sec to make 5000 loop
It is a winform application running on windows.
Thanks for your help
I would like to make a thread loop to do calculations according time , like a PID.
For example If the loop run for 5sec and I make only a increment by one the output shoud be 5000 if my loop time is 1ms.
I've tried thread.sleep(1) in my thread loop but it is too slow, I've tried something like this
C#:
UInt16 i = 0;
DateTime _Start = DateTime.Now;
DateTime _New = DateTime.Now;
do
{
while ((DateTime.Now - _New)< TimeSpan.FromMilliseconds(1)) ;
_New = DateTime.Now;
i++;
//Thread.Sleep(1);
} while (i < 5000);
TimeSpan _Span = DateTime.Now.Subtract(_Start);
Console.WriteLine("dt {0}", _Span);
but not efficient too, it take 7.6sec to make 5000 loop
It is a winform application running on windows.
Thanks for your help