|
ka ka ka ka ka
Yes.......
|
|
|
|
|
The System.Timers.Timer is too slow in my application. Can you guys please give me a hint?
I wrote this short Code to test the timer.
At first I create a timer:
private void button2_Click(object sender, EventArgs e)
{
System.Timers.Timer Timer;
Timer = new System.Timers.Timer();
Timer.Interval = 20;
Timer.Enabled = true;
Timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
}
Afterwards I simple dispolay the elapsed time in a label, so that I can compare theese result with a stop watch:
private void OnTimedEvent(object source, ElapsedEventArgs e)
{
Invoke(new MethodInvoker(delegate
{
label1.Text = (Convert.ToInt32(label3.Text) + 20).ToString();
}));
}
|
|
|
|
|
Why not just use the Stopwatch class instead? As you currently have this implementation, you aren't actually displaying the elapsed time - you're just displaying an arbitrary value (oh, and if you use Debug.WriteLine in the OnTimedEvent, you can track the elapsed in the output window without having to marshall across to the UI thread.
|
|
|
|
|
Thanks for the tipp. I have a continuos signal and need to take measurements every 20ms. Can you give me a codeexample, how to use stopwatch in this case? Actually I think I need a thread that constantly tests if my stopwatch elapsed time is divisible by 20ms?
|
|
|
|
|
Hi,
Measure it manually and checking everytime for elapsed time never good option. timer is for that purpose. you are calling method every 20ms it means your code is executed 50 times per second. Please elaborate your actual problem. Why you need to execute function after 20ms ?
Thanks
-Amit Gajjar
|
|
|
|
|
Quote: Why you need to execute function after 20ms ?
As i said, I have contious time signal (by Leap Motion) and I want to sample it with 50 Hz, or at least 40 Hz.
|
|
|
|
|
|
Windows is not a real-time OS. 20 ms means that the event will be triggered "somewhere" after 20 ms passed, not "exactly" after 20 ms.
Don't, unless you're sure.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Member 9940073 wrote: The System.Timers.Timer is too slow in my application.
That's beautifully vague but I'll assume that you are wondering why the real timer interval is fairly consistent but is is not 20ms.
The timer does not have a millisecond resolution and although the programmer may set different values e.g. 17, 18, 19 or 20 ms the actual interval obtained may not vary. On most systems the resolution of the timer is 15.625 ms which means that the real timer intervals can only be multiples of 15.625ms, i.e. 15.625, 31.25, 46.875 etc. So when you set 20ms, what you actually get is rounded up to the next possible real interval, i.e. 31.25ms.
As Eddy said in his reply the operating system is not real time and the timer event may be delayed slightly beyond the rounded up interval.
Alan.
|
|
|
|
|
Precision - I like that! I knew that the resolution was around 16ms on most systems but now I know its 15.625ms.
Timers have been rubbish for ages, but I think I recall being surprised that the one on my PC is actually considerably more accurate than that. But, as you say when dealing in the ms range I'd have thought that waiting for a context switch could certainly bump things into the next ms or so.
Regards,
Rob Philpott.
|
|
|
|
|
For most purposes, the advice that (always reliable) Pete O'Hanlon gave you, to use an instance of System.Diagnostics.Stopwatch: is what you need.
But, given your requirements, you may also want to examine this April 13, CodeProject article: "Microsecond and Millisecond C# Timer," by Ken Loveday: [^].
And, possibly other resources on high-precision .NET timing at: [^].
However, I do not know if any of the techniques above can meet your requirements: I have never needed higher-precision timing than that provided by 'Stopwatch.
When you use the 'Stopwatch class, I hope you don't make the same stupid mistake I made recently [^], and use Stopwatch.Elapsed.Milliseconds, thinking that gets the total time, instead of Stopwatch.TotalElapsedMilliseconds, as was kindly pointed out to me by Alan N. here on this forum: [^].
good luck, Bill
~
“This isn't right; this isn't even wrong." Wolfgang Pauli, commenting on a physics paper submitted for a journal
modified 30-Jul-13 12:16pm.
|
|
|
|
|
I have successfully used (via P/Invoke wrappers I wrote) both the MultimediaTimer [now depreciated but has been available on every system I have ever tested] and TimerQueueTimer with greater precision than you are requiring.
I can dig the code out if you would like it, but it didn't take me too long to knock it up from scratch as I remember.
They are not recommended for general purpose timers however and it is very rare that level of precision is required!
|
|
|
|
|
If you 'need' to do this rather than 'want' to do it then I suspect you might be forced to write a OS driver. Doing that should give you complete control to collect the data at the interval you want.
The driver would do nothing but the following
- Collect the data at the required interval
- Put the data in a buffer
- Provide a method callable from an external app that returns the current buffer.
Then your application can ask the driver for the data and do whatever you want with it.
If you just 'want' to do it then some of the other suggestions will probably require sufficient functionality to get the data most of the time.
|
|
|
|
|
I am Making Dashbord in .net C#. I want to open some module whis is made in VB6. when i add module dll in Dashbord open form but grid not display
|
|
|
|
|
Please give some more detail. We cannot see your screen so it is impossible to guess what your problem may be.
Use the best guess
|
|
|
|
|
Hi all
Please clear my doubt.
I have one server system where i installed sql server.
5 client machines accessing that.
now suppose if there is any power fluctuation like it's coming for 5 min and again going and so on.
So for this kind of situation, how to save the data or how to update the database each second.??
Is it possible that at a time we update the client database also and server database also.?
i.e at button click it should update both client and server database..
Please help..
|
|
|
|
|
Sound like mirroring to me and yes that's a database function and not on the client. Mirroring is generally a rather complex setup between major servers I don't think it applies to mirroring to a client machine.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
It is possible, you need to look up database mirroring / database replication.
Please ask further question on this topic in one of the specialised SQL forums (it can get quite complicated depending on your needs), this forum is devoted to c#. Note that if you do it properly it will be transparent to the database users.
|
|
|
|
|
Ok...thanks..
|
|
|
|
|
Same problem I faced earlier when user need to sync data with more than two databases. we keep insert, update delete operation with data in a queue and create window service that sync queued operations with other databases(may or may not be same).
It will sync deferential data not all.
|
|
|
|
|
Hi. Is there a way to convert html to chm file programmatically using C# WinForms?
|
|
|
|
|
|
|
Hi guys. I need suggestions on C# projects that are not too hard but not too simple since it might be not pleasant for our professor. My group mates and I need to do an object oriented program/system and we cannot think of anything as of now since we are not really good at programming. Anyway, your suggestions are appreciated. Thanks!
|
|
|
|
|
Is this for a computer science course of some description? If I were looking to do something like this, I'd pick something that interests me and look at writing a project based on that. The reason for this is simple - if it's something I'm interested in, then I already have some knowledge about the topic. That makes it easier for me to design the application.
|
|
|
|