• Register
0 votes
356 views

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

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.

e.g.

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

....

//Adding to DownloadAsync() method
myWebClient.DownloadDataCompleted += (s, e) => {
 isDownloading = false;
 signalDownloadComplete.Release();
}
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 48 views
48 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 25 views
25 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 Raphael Pacheco 4.9k points
1 vote
1 answer 35 views
35 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 10 views
10 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 Raphael Pacheco 4.9k points
0 votes
1 answer 10 views
10 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 Sofi55 1.1k points