You're blocking the UI thread by performing long running non-UI work in the UI thread. You need to offload that work to another thread and then update the UI with the results of that work.
A BackgroundWorker
is specifically designed for this exact operation. Compute the Result
in the DoWork
event handler and set that result, then display the Result
to the UI using the RunWorkerCompleted
event handler.
The other option, if you're using C# 5.0, is to use await
, which would let you write:
public async void updatePerfInfo()
{
lblCPUMaxValue.Text = await Task.Run(()=>formatMhzGhz(maxCPUSpeed()));
lblCPUCurrentValue.Text = await Task.Run(()=>formatMhzGhz(CPUSpeed()));
}