I am inside a threat updating a graph and I go into a routine that makes a measurement for 4 seconds. The routine returns a double. What I am noticing is that my graph stops showing activity for 4 seconds until I am done collecting data. I need to start a new thread and put the GetTXPower() activity in the background. So in other words I want GetTXPower() and the graph charting to run in parallel. Any suggestions?
here is my code:
stopwatch.Start();
// Get Tx Power reading and save the Data
_specAn_y = GetTXPower();
_pa_Value = paData.Start;
DataPoint.Measurement = _specAn_y;
//Thread.Sleep(50);
double remaining = 0;
do
{
charting.stuff
}
uxChart.Update();
I suggest looking into Task Parallel Library.
Since you also need the result back from
GetTXPower
, I would use aTask<double>
for it.Depending on when you need the result, you can query if the task has completed by checking
task.IsCompleted
or alternatively block the thread and wait for the task to finish by callingtask.Wait()
. You can fetch the result throughtask.Result
property.An alternative would be to add a continuation to the initial task: