The culprit for freezing is this:
return await new Task<int>(() =>
{
return pageData.Length;
});
This Task
constructor doesn't start the task, so you're creating a Task
that isn't running. When you await
on it in GetStringLength
you're going to be waiting forever for the result.
You can either start the task manually:
var result = new Task<int>(() =>
{
return pageData.Length;
});
result.Start();
return result;
or use the Task.Run
static method, which will create and start the task:
return Task.Run(() =>
{
return pageData.Length;
});