|
Hello,
Thanks for the reply. I don't want to be rude, but it does not help to much.
1. It's sorted chronologically
2. I am already using multimedia timer, and I don't need 1000000 millisecond precission. The time is like : hh:mm:ss,mmm (first 3 digits from milliseconds).
3. This is what I don't know how to do. As I said, I tried in a while(true) loop, and it worked perfectly, but that's not efficient. That's why I was thinking of a custom event. The windows forms timer is similar to what I want, but it's not good. The windows forms timer receives an interval and you call start. Instead of this, I would need something like SetFinalTime(time,WhatToDo). When time equals the system time, than execute the function WhatToDo . That would be my idea, but I don't know how to implement it.
Believe me,I did my reading
4. They are close, yes, but I will figure that out on the way. First I need point 3 solved ... the event (or any other suggestion).
Thanks!
Vlad
|
|
|
|
|
So you have the necessary tools in your tool box. Switch on the brain cells.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
I really tried, believe me, but I have no ideas how to do it. SImply no ideas. If I had ideas, I wouldn't have posted here
|
|
|
|
|
If (as you say to Luc) the data is sorted in date time order then why not work out the number of seconds between now and the next message being due, and set up a timer for that interval. Start the timer as a single-shot, and when it fires...
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
It's true that while running through a loop constantly is not very efficient it is going to be the most accurate for you. What you really need to decide is how accurate you really need this to be.
You say that when you match up with one of the times you have you will send data to a TCP client, sending data over the network (unless the destination is actually your own machine) will have a small delay of some milliseconds to actually get sent and then it will be a little longer before it arrives at where it needs to be. That being the case you may be able to set up a standard System.Timers.Timer and use a reasonably small Tick (say 50 milliseconds or something).
All you'd need to do then is know the current time and check to see if there are any times in your list that you have gone past since the last time you checked. In this case there would be a maximum delay of 50ms since the time in your list but of course you could lower it for a little more accuracy (Keeping in mind that at the best of times the standard timer will only get called every 20ms) or indeed make the gap larger which would save some of your precious CPU time.
There's no way you're going be able to set up any kind of event that will be fired accurately down to the millisecond, even with a while loop and a performance counter it's easily possible that you may skip past a time (and therefore miss the event or fire it 'late'). So like I said you need to decide how much delay you can tolerate if the answer is 'None' then you will have to stick with your while loop because that is as accurate as it's going to get
My current favourite quote is: Punch them in the face, see what happens!
-SK Genius
|
|
|
|
|
I think I have a decent solution to your problem which would give the accuracy you want without killing the CPU:
class bleh
{
List<DateTime> times;
DateTime next;
bool quit = false;
void main()
{
while(!quit)
{
bool resting = false;
next = ...;
do
{
resting = false;
TimeSpan diff = next - DateTime.Now;
if(diff > someVal)
{
resting = true;
sleep;
}
}
while(resting);
while( true )
{
if(DateTime.Now >= next)
{
fire event;
break;
}
}
}
}
}
You'd want to be running this in a separate thread so it doesn't interfere with your main application and you'll want to replace DateTime.Now and whatnot with queries to your multimedia timer and you may also have to add some stuff for events that are very close together.
Basically if there is a large enough gap in time before the next event you should be able to afford to put the thread to sleep and when you get close to the event you will have to go into the while loop to make sure that the event is fired as close to the specified time as possible. What amount of time you use to switch between sleeping and looping is entirely up to you and I imagine will involve some experimentation.
Well, I hope that gives you some idea on what you could do to improve performance, without (hopefully) sacrificing too much accuracy.
My current favourite quote is: Punch them in the face, see what happens!
-SK Genius
|
|
|
|
|
example ebout style button
|
|
|
|
|
question
See how annoying that is?
Do you have a question?
Read the instructions at the top of the page "how to get an answer to your question".
Then edit your post to comply. Then, maybe, you will get help.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
See here. This will help you ask a question so that you can get an answer.
My signature "sucks" today
|
|
|
|
|
Don't you know, how to phrase a complete sentence?
"I love deadlines. I like the whooshing sound they make as they fly by." (DNA)
|
|
|
|
|
Hello,
I have developed an point of sale desktop application. I have integrated the Customer Display too with this app. Now i am facing a little issue, When ever Customer display writes some thing on it, it takes around 3 seconds to write always whatever i write, 3 Seconds is too much and its slowing down the speed of app. ANy suggestions..?
|
|
|
|
|
tell us more about the "Customer Display". Is it a commercial product? what is the interface (hardware and software)? is there a handshake protocol involved? maybe show relevant code (inside PRE tags!).
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
The first step is to time the different steps of the process to identify which is taking the most time. Often the bottleneck isn't where you suspect it is.
Only after you know what's slowing down the process can you start to correct it.
|
|
|
|
|
Hello,
When i am trying to copy stringbuilder to string it copies the same string twice or 3 times
for example if i do:
stringbuilder temp=new stringbuilder();
string temp1;
temp1=temp.tostring();
if temp="abc";
then temp1 gets- "abcabcabc"
why is that?
|
|
|
|
|
Try !ispostback
try and try untill reach success..
|
|
|
|
|
|
IsPostback is relevant to ASP.NET. The OP did not say what environment he was using so your answer could be completely irrelevant and worse misleading.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
You haven't shown any code that actually adds values to the stringbuilder. Where is that? Are you calling it multiple times perhaps.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I fount my mistake.
I had a method that returns a stringbuilder and receives a stringbuilder.
for example:
private stringbuilder method1(stringbuilder temp)
{
temp.append("abc");
}
private void main_method()
{
stringbuilder main=new stringbuilder();
main.append(method1(main));
}
something like that
|
|
|
|
|
michaelgr1 wrote: if temp="abc";
Hmmmm....
Show us as much of the actual associated code as you can...
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hi. i have been wondering for a while, is there any option to retrieve rows from a SQL Server with a startRecord e.g. select top 20 records from position 25, Without any WHERE conditions (without WHERE ID > 25)..
Please advice.
Thanks
|
|
|
|
|
I think there a one way to do this
Retrive all data columns and fill it into dataset and loop it.
try and try untill reach success..
|
|
|
|
|
Hello,
I currently have an unmanaged DLL written in C++ and I can call the exported methods in this DLL from my C# app without any problems and it works quite well.
Now, I need to call from this DLL a method in my managed app. Is it possible to do so? What do I need to do so that the managed method is visible and available to the unmanaged DLL?
Thanks,
Keith
|
|
|
|
|
|
or look at "delegates" and "two-side logging" in this article[^].
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|