• Register
0 votes

Problem :

Facing following ASP.Net error

an asynchronous module or handler completed while an asynchronous operation was still pending.

6 5 3
6,930 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

The method named myWebClient.DownloadStringTaskAsync runs on a separate thread and also it is non-blocking. A possible solution is to  DownloadDataCompleted event handler for myWebClient and a SemaphoreSlim class field.


private SemaphoreSlim signalDownloadComplete = new SemaphoreSlim(0, 1);
private bool isDownloading = false;


//Adding to DownloadAsync() method
myWebClient.DownloadDataCompleted += (s, e) => {
 isDownloading = false;
isDownloading = true;


//Adding to block main calling method from returning until download is completed 
if (isDownloading)
   await signalDownloadComplete.WaitAsync();

This will resolve your issue

9 7 4
38,600 points

Related questions

0 votes
1 answer 7 views
Problem: are you missing a using directive or an assembly reference.
asked Feb 18 charles mathews 3.8k points
0 votes
1 answer 61 views
Problem : I am having my radcombo machines on aspx page and whenever I try to select any option from them then it gives me following `Server Error in '/' Application. Exception Details: System.InvalidOperationException: Operation is not valid due to the current state of the object. My Version Information: Microsoft .NET Framework Version: 2.0.50727.3634 ASP.NET Version: 2.0.50727.3634
asked Dec 2, 2019 alecxe 7.5k points
0 votes
1 answer 30 views
Problem: Currently I have the table called Student in the database with some of the values and I am trying to display the values in the webgrid with the help of entityframework. I have done exactly the same kind of work before many times using the Ado.net, but ... I assign the VAR value to List also is this my correct approach? Kindly guide me in fixing my problem related to Entity Framework.
asked Jul 3, 2020 Raphael Pacheco 4.9k points
1 vote
1 answer 46 views
Problem : While binding the dropdown in MVC, I often face following error: There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key country. Please find below my View for your reference : @Html.DropDownList("country", (IEnumerable<SelectListItem>)ViewBag ... .countryid.ToString() }); } ViewBag.mycountrydrop = myitem8; return View(); I do not know how to resolve above error.
asked Dec 28, 2019 alecxe 7.5k points
1 vote
1 answer 16 views
Problem: I am having fundamental knowledge on C#. Currently I am unable to connect to the HTTPS server with the use of WebRequest as I am facing below error message: "The request was aborted: Could not create SSL/TLS secure channel." I understand that my ... my server never really validates a certificate and it fails with a above error. Kindly guide me in fixing above certificate related error.
asked Jun 30, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 14 views
I have a hash of words and respective frequencies, that I want to order by frequency. Sorted Dictionary orders by key, not value. Some resort to a custom class, but is there a cleaner way?
asked Aug 31, 2020 Sofi55 1.1k points
0 votes
1 answer 121 views
In previous versions of .Net, it was possible to override bool AuthorizeCore(HttpContextBase httpContext). But this no longer exists in AuthorizeAttribute. What is the current approach to making a custom AuthorizeAttribute?
asked Aug 29, 2020 Aliza313 720 points
0 votes
1 answer 26 views
0 votes
1 answer 44 views
0 votes
1 answer 14 views
Problem: I am very new to C# and Asp.net. I have tried to write the below code: protected void Page_Load(object sender, EventArgs e) { num = Convert.ToInt32(Request.QueryString["RegNo"].ToString()); if (!IsPostBack) { BindTextBoxvalues(); }     } But my above code is ... for the past few days, I have also taken the help from the colleagues in my team but still I am facing the same old error.
asked Sep 3, 2020 Raphael Pacheco 4.9k points