Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9087675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:45:01+00:00 2026-06-16T21:45:01+00:00

I have the following extension method: internal static string ReadLine(this DataReader stream) { Task<string>

  • 0

I have the following extension method:

internal static string ReadLine(this DataReader stream)
{
   Task<string> line = ReadLineAsync(stream);
   // line.Wait(); - Not Required, as next call blocks
   return line.Result;
}

It’s basically a Synchronous method call wrapper for an Asynchronous method call that returns a string. The code works fine if I step through it line by line, however it seems that if I let it execute freely, I encounter an indefinite block. Any ideas?

Related to a previous question I posted: How can I update my API to use the async keyword without using await for all callers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T21:45:02+00:00Added an answer on June 16, 2026 at 9:45 pm

    As some commented on the answer to your other question, if you use Task.Result in a GUI application, you may cause a deadlock (as I explain in detail on my blog).

    In short:

    • You start the asynchronous operation on the UI thread. Note that the task line represents the ReadLineAsync method, and will complete when that method completes.
    • ReadLineAsync calls await on some operation that is incomplete. This causes ReadLineAsync to return an incomplete task (line).
    • You block the UI thread waiting for line to complete.
    • When the awaited operation completes, it schedules the remainder of ReadLineAsync to the UI thread.
    • The UI thread cannot complete ReadLineAsync because it is synchronously blocked waiting for ReadLineAsync to complete. Deadlock.

    See my answer to your other question for a way around this deadlock. In short:

    • Use ConfigureAwait(false) everywhere.
    • Change your error handling to account for Result wrapping its errors in AggregateException.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following extension method: public static void ThrowIfArgumentIsNull<T>(this T value, string argument)
I have the following extension method public static T Field<T>(this DataRow row, string columnName)
I have the following extension method: public static string ToPropertyName<T,E>(this Expression<Func<E, T>> propertyExpression) {
I have the following extension method public static bool IsValidCurrency(this string value) { CultureInfo
I have following extension method written: static public IQueryable<OutboundPattern> ByClientID(this IQueryable<OutboundPattern> qry, int clientID)
I have the following extension method public static class ListExtensions { public static IEnumerable<T>
I created the following extension method: public static bool HasHostAndUrl(this HttpSessionStateBase session) { return
i have the following linq extension method, which returns an IEnumerable. This means, that
I have declared the following extension method: public static T FindAncestor<T>(DependencyObject obj) where T
I have the following method: public static TEventInvocatorParameters Until <TEventInvocatorParameters, TEventArgs>(this TEventInvocatorParameters p, Func<TEventArgs,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.