Freezing UI with async/await
I have some code running that will freeze up if you grab and move the
window while it is loading. I'm not sure what the problem is but thought I
would post my code since I am fairly new at working with async/await and
just wondering if there is some problem with my logic. I'm not saying this
is causing the problem, I've just searched and seen other problems that
with UI freezing up and async/await comes up often. Any help would be
appreciated.
private async void BuildChart()
{
DateTime date = DateTime.Today;
using (Database db = new Database())
{
await BuildActual(date, db);
await BuildActual(date.AddDays(1),db);
}
}
private async Task BuildActual(DateTime date, Database db)
{
List<TimeSeries> actualValues = await
Task<List<TimeSeries>>.Factory.StartNew(() =>
{
try
{
var wind = DoStuff(date, db);
if (wind == null) return null;
if (wind.Count == 0) return null;
return MakeTimeSeries(wind);
}
catch
{
return null;
}
});
try
{
if (actualValues == null) return;
DoMoreStuff(actualValues);
}
catch (Exception ex)
{
Logger.Log(ex);
}
}
Thanks.
No comments:
Post a Comment