record data in every 10 milliseconds

I am working on a .net application in which I have to record data and perform calculations and also at the same time add entries into the database. This complete process should be in each 10 milliseconds of time span Elapsed. This is kind of real time data analysis in c#.

I have done lot of research in order to achieve this, with threads, async/await and thread pools but still not able to get the desired output. Basically I want to record data in every 10 milliseconds and store it in database. Below is the code sample i was working on.

private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Start();
        }
        async void InsertData()
        {
            timer1.Stop();
            int i = await Insert(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture));
            timer1.Start();
        }

        async Task<int> Insert(string value)
        {
            ThreadApp objThread = new ThreadApp();
            objThread.value1 = value.ToString();
            db.ThreadApps.Add(objThread);
            db.SaveChanges();
            int i = 1;
            return i;
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            InsertData();
        }

Desired Output:

Please if anyone can suggest me how can i achieve this requirement.

链接地址: http://www.djcxy.com/p/57480.html

上一篇: 如何获得两点之间的时间?

下一篇: 每10毫秒记录一次数据