How to check a data stream every 5 seconds

I have a program that checks a streaming data feed every 5 seconds, then makes some calculations and then fires some events, then back to checking data. What is the best way(most efficient) way to do this. Here is my basic structure, however my program freezes after running for more than a few hours(I want to run it 24 hrs a day) I know that multithreading is needed but not sure how to do this.

Basic structure:

Main program
Get Data
Calculations
Do events
loop back to Get Data

Thanks in advance.




Answer this question

How to check a data stream every 5 seconds

  • deyanp

    It is taking realtime streaming stock and currency quotes(trades) and making calculations with that info to trade. I am pretty sure I need a new thread, just not up to speed on how to do it in C#(I am new with extensive VB experience).

    Thanks

  • cmsmith81

    you would be advised to use a Timer and set the interval to every 5 seconds (timer interval is measured in ms) and then do your data checking there and raise events or whatever.

    depending on what you are doing, you may require to spin up another thread to check the data and perhaps do the timer interval in there than the main thread (UI thread).

    Generally the timer should be used. Can you tell us what the application does From this, we can then help you in deciding if you require another thread to do your calcs/raising events in



  • Fran Garcia

  • How to check a data stream every 5 seconds