You can start a new thread inside your tick event.
That way you will spend very little time blocking the GUI.
You can start reading about threads here:
Threading (C# and Visual Basic)[
^]
And here is a short example:
using System.Threading;
private void Sampling_Timer_Tick(object sender, EventArgs e)
{
Thread worker = new Thread(new ThreadStart(DoSomething));
worker.Name = "Doer";
worker.IsBackground = true;
worker.Start();
}
private void DoSomething()
{
Stopwatch sw = new Stopwatch();
sw.Start();
sw.Stop();
string elapsedTime = sw.ElapsedMilliseconds.ToString();
}
[UPDATE]
I added a Stopwatch that can be used to measure the time you spend in the worker method.
If you spend more than one second reading values from the device you have a little problem, as the next timer event will trigger before you have finished reading from your device.
You basically have two ways to solve this dilemma:
1. Read fewer parameters, if that is possible.
2. Make the time between events long enough for all the parameters to be read.
The solution with adding a lock will not work well in the long run as you will soon pile up a queue with requests to read from the device and this queue will just be longer and longer until you run out of resources.
There are several other methods to achieve the same result, but this is pretty simple to start with.
For example, the
BackgroundWorker
class can be used as well.