|
I have a while(true) loop runing in a thread that's currently just updating UI, but will eventually be controlling a peice of external hardware. The debug text it's outputing includes a timestamp in ms (DateTime.Now.ToString("HH:mm:ss.fff") ), but it's tick rate is approximately 10ms. I tried doing finer grained control by adding a 1ms Sleep call and incrementing a counter, but vagarities of the scheduler meant I was getting anywhere between 2 and a half dozen updates during the course of a 10ms DateTime tick.
Is there a more finegrained option available, or is the 10ms of DateTime the best I can do?
|
|
|
|
|
AFAIK Windows is not accurate to that sort of timespan. I dont think there is any way to get a millisecond-accurate application using a win OS.
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
|
|
|
|
|
That's more or less what I thought. Thanks for confirming it.
|
|
|
|
|
Can you not use multimedia timers for this?
Regards,
Rob Philpott.
|
|
|
|
|
Probably. I didn't know they existed until now, I'll give on a try in a little bit.
|
|
|
|
|
No good. I need to support legacy OSes, and according to MSDN this is an XP only capability.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_timesetevent.asp
-- modified at 14:56 Thursday 4th May, 2006
the two other api calls I'd need: timeGetDevCaps and timeKillEvent, are available on NT, are they also used for a standard timer, or's MSDN wrong?
|
|
|
|
|
I really have to think back about this. Yonks ago, I wrote some MIDI sequencing nonsense and if you used the standard timers your computer would happily go in to some background task and everything would slow down. Multimedia timers were the answer.
I remember seeing a friend die on stage from exactly this (with Cakewalk, a shoddy bit of PC sequencing software), his laptop had decided to defrag itself or some other useful task without realising there was a show on. Not good.
Apparantly, this is one of the reasons why the Mac was always favoured over the PC as the musician's PC. But this doesn't help answer your question...
Thinking back to the advent of 95 and 32 bit Windows, I think some 32-16bit thunking layer was needed to keep timers accurate. I followed your link and sure enough these timers are described as XP only, but I know well I used them maybe ten years ago.
What legacy OSs are you developing for?
Regards,
Rob Philpott.
|
|
|
|
|
Rob Philpott wrote: I followed your link and sure enough these timers are described as XP only, but I know well I used them maybe ten years ago.
Ok, I'll cobble up a testapp to try it. THe one implementation I found on CP has a 2.0 demo I can't use (need 1.1 for legacy compatabilty), and didn't want to go blind in writing something if I could avoid it.
Rob Philpott wrote: What legacy OSs are you developing for?
2k and NT4.
|
|
|
|
|
You can use these:
[DllImport("kernel32.dll")]
internal extern static UInt32 QueryPerformanceCounter(out UInt64 counter);
[DllImport("kernel32.dll")]
internal extern static UInt32 QueryPerformanceFrequency(out UInt64 frequency);
Divide the counter by the frequency to get seonds. It will give you an accuracy down to at least a microsecond.
---
b { font-weight: normal; }
|
|
|
|
|
Can these be used to build a well behaved timer, or would I have to use the same CPU hogging while (true) approach as I did when looking at DateTime.Now?
|
|
|
|
|
I recognize those. That's the raw Win32 API for the "High Resolution Timer". It's been around for years and is the baseline timer for programs like Windows Media Player and midi players that need to keep pace or the playback of video and audio is goofy.
It's fairly straightforward (at least it used to be, who knows under the modern .NET managed world of today). Give it a try. The only thing you have to do is check to verify that a High Performance counter is available by verifying the return value of QueryPerformancecounter does not return 0. I've actually never seen a system return 0, but there always a first time.
I'm surprised and not surprised that multimedia timers only work under XP. Especially since I've been using them in Visual C++ dating back to version 5.0 and windows 95.
Just one more example of a mediocre/partial port of basic functions under Csharp and .NET. Oops, sorry for the rant, umm...Csharp is gr8 .NET is awesome...there, that's better.
|
|
|
|
|
Hi..
I wanted to make a windows application setup project..for that reason i have downloaded the Visual studio BootStrapper plug-in but when i install my application setup (using a CD) on another computer the setup asks the user to install the .NetFramework even that the same folder on the CD has the .NetFramework redistributable file..I dont want the setup to ask the user for anything.
How could i solve this problem?.. please help
|
|
|
|
|
The goal of the bootstrapper is to see if the requirments of your application exists on the client PC or not, if yes it starts the setup of your application, otherwise it starts the setup of those requirments (.NET in your case), And the .NET framework can't be installed without the user agreement, ofcourse.
------------------------------ "The Soapbox has been so ..."
|
|
|
|
|
Thank you for your respond...
But i want it to use the .NetFramework redistributable file instead of telling the user to install the .NetFramework from the internet.Could you tell me how to do this?
|
|
|
|
|
You must configure the bootstrapper from the build menu in your projects, so that it starts the setup from the same directory.
------------------------------ "The Soapbox has been so ..."
|
|
|
|
|
Thank you I will try it.
|
|
|
|
|
I have an arraylist full of strings, some of which will hopefully be identical (ie every entry will not be unique). How can I go about finding the most common string, the string that occurs most often? Does .NET give me any nice methods for doing such or will I have to do it myself?
I can think of one method; by making a 2D array, one dimension for storing the string, one dimension for storing the number of times it appears. However I dont think you can make a dynamically self sizing 2D array (like an arraylist) can you? If this is true I would need the array to be large to take care of the unknown number of items in the array list, and would end up being very slow.
Any help is much appreciated.
|
|
|
|
|
You could create a Hashtable where the keys are strings and the values are ints (the number of occurences of the string). Loop over the ArrayList of strings and either add each string to the table with a counter of 1, or increment the counter if the string is already in the table. When you're done, loop over the Values of the table and look for the highest counter.
Josh
|
|
|
|
|
Subterranean wrote: However I dont think you can make a dynamically self sizing 2D array (like an arraylist) can you?
You could make an arraylist populated with arraylists! That gives you something similar to a 2-D dynamic, jagged array.
However, if you're just storing the number of times a string appears you don't need a 2-D array at all. You just need to store an int with the frequency for each string.
You could create a class that wraps your string (as a member) and includes a member for the number of times it exists and store that in an ArrayList.
|
|
|
|
|
How to display data of datagrid into crystal report.
|
|
|
|
|
hi i think you need to generate a report for the dataset witch is supplying data to grid.
first you have to place the crystal report viewer on your form then you have to add crystal report page your project.then you have to connect the data base and particular table with that report page and allign the page.
now come to the form,
1.create the object for that crystal report page file,assume that name is crys1.rpt
then crys1 cry=new crys1();
2. set the logon password and uname for sql server
cry.SetDatabaseLogon(uname,password);3. set the report datasource
cry.DataSource=dataset;4.set the report source to crstalreport viewer
crystalReportviewer1.ReportSource=cry;
5.Bind the data source
crystalReportViewer.DataBind()
|
|
|
|
|
i'm creating a software that paint and draw on a picturebox, but it is very slow.
How can i accelerate it?
|
|
|
|
|
You may better draw on a panel not a picturebox.
------------------------------ "The Soapbox has been so ..."
|
|
|
|
|
|
Are you using the paint event to draw on top of the picturebox, or are you drawing on the image in the picturebox?
---
b { font-weight: normal; }
|
|
|
|