Click here to Skip to main content
15,896,726 members
Home / Discussions / C#
   

C#

 
QuestionTime event? Real time data send Pin
sodevrom31-May-10 6:46
sodevrom31-May-10 6:46 
AnswerRe: Time event? Real time data send Pin
Luc Pattyn31-May-10 7:03
sitebuilderLuc Pattyn31-May-10 7:03 
GeneralRe: Time event? Real time data send Pin
sodevrom31-May-10 7:12
sodevrom31-May-10 7:12 
GeneralRe: Time event? Real time data send Pin
Luc Pattyn31-May-10 7:14
sitebuilderLuc Pattyn31-May-10 7:14 
GeneralRe: Time event? Real time data send Pin
sodevrom31-May-10 7:18
sodevrom31-May-10 7:18 
AnswerRe: Time event? Real time data send Pin
OriginalGriff31-May-10 9:59
mveOriginalGriff31-May-10 9:59 
AnswerRe: Time event? Real time data send Pin
Anthony Mushrow31-May-10 14:47
professionalAnthony Mushrow31-May-10 14:47 
AnswerRe: Time event? Real time data send Pin
Anthony Mushrow1-Jun-10 4:49
professionalAnthony Mushrow1-Jun-10 4:49 
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;
      //Search through your list and find the next time that will be reached
      next = ...;

      do
      {
        resting = false;
        TimeSpan diff = next - DateTime.Now;

        //If the time difference between now and the next event is greater
        // than some tolerable value, sleep for a while
        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


Questionstyle button Pin
toba tavasoli31-May-10 5:09
toba tavasoli31-May-10 5:09 
AnswerRe: style button Pin
OriginalGriff31-May-10 5:12
mveOriginalGriff31-May-10 5:12 
AnswerRe: style button Pin
Abhinav S31-May-10 6:00
Abhinav S31-May-10 6:00 
AnswerRe: style button Pin
Smithers-Jones31-May-10 8:07
Smithers-Jones31-May-10 8:07 
QuestionSpeed Issue in POS Customer Display Pin
NetMan201231-May-10 4:34
NetMan201231-May-10 4:34 
AnswerRe: Speed Issue in POS Customer Display Pin
Luc Pattyn31-May-10 4:51
sitebuilderLuc Pattyn31-May-10 4:51 
AnswerRe: Speed Issue in POS Customer Display Pin
Alan Balkany1-Jun-10 3:50
Alan Balkany1-Jun-10 3:50 
Questionstringbuilder to string Pin
michaelgr131-May-10 1:22
michaelgr131-May-10 1:22 
AnswerRe: stringbuilder to string Pin
Rajeshwar Code- Developer31-May-10 1:31
Rajeshwar Code- Developer31-May-10 1:31 
GeneralRe: stringbuilder to string Pin
michaelgr131-May-10 1:32
michaelgr131-May-10 1:32 
GeneralRe: stringbuilder to string Pin
Not Active31-May-10 2:34
mentorNot Active31-May-10 2:34 
AnswerRe: stringbuilder to string Pin
Not Active31-May-10 2:35
mentorNot Active31-May-10 2:35 
GeneralRe: stringbuilder to string Pin
michaelgr131-May-10 2:46
michaelgr131-May-10 2:46 
AnswerRe: stringbuilder to string Pin
#realJSOP1-Jun-10 4:56
professional#realJSOP1-Jun-10 4:56 
QuestionDataAdaptor.Fill startRecord Pin
Eli Nurman31-May-10 1:18
Eli Nurman31-May-10 1:18 
AnswerRe: DataAdaptor.Fill startRecord Pin
Rajeshwar Code- Developer31-May-10 1:34
Rajeshwar Code- Developer31-May-10 1:34 
QuestionHow to call from an unmanaged DLL to managed code Pin
Keith Vitali31-May-10 0:53
Keith Vitali31-May-10 0:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.