0

I'm writing code with async/await for some requirement that I have to write some method like this

public bool Foo()
{ // not async
    return Foo_Async().Result;// get freeze
}

public Task<bool> Foo_Async()
{
    bool foo1Result = await Task.Run(()=>Foo1());
}

When execute, app gets freeze.

5
  • 5
    Yes ofcourse your app freezes. The call yo .Result is blocking. Its waiting for the task to finish.
    – ckruczek
    Feb 3, 2016 at 6:15
  • Where do you need the result of Foo()? Feb 3, 2016 at 7:19
  • hi @ckruczek I just want to run Foo_Async synchronously and return result after finished with await Task inside. Feb 3, 2016 at 16:07
  • Well I am sorry to say that but thats not how the async part of c# was designed for. You better go and read a tutorial about it again and again and again and....well you know the rest.
    – ckruczek
    Feb 3, 2016 at 17:48
  • 2
    This looks like the async deadlock.
    – svick
    Feb 3, 2016 at 19:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.