473,379 Members | 1,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Asynchronous HTTPModule executes synchronously ?

Hi,

I need to write asynchronous HTTPModule which will sometimes execute long
job. I've written it using AddOnBeginRequestAsync but it still executes
synchronously - I am checking performance counters but after running X
requests which executes this "asynchronous" module all other requests go to
application queue - so it executes synchronously.

Code is based on the following article
http://msdn.microsoft.com/msdnmag/is...WickedCode/#S3

This is my sample code

public class RequestDelayModule : BaseHTTPModule {

protected override void Init() {
base.Init();
this.Application.AddOnBeginRequestAsync(new
BeginEventHandler(BeginRequest_AsyncBegin), new
EndEventHandler(BeginRequest_AsyncEnd));
return;
}

delegate void ABR(HttpContext Context);

IAsyncResult BeginRequest_AsyncBegin(object sender, EventArgs e,
AsyncCallback cb, object state) {
return new ABR(Application_BeginRequest).BeginInvoke(null, cb,
this.Context);
}

void BeginRequest_AsyncEnd(IAsyncResult ar) {
return;
}

void Application_BeginRequest(HttpContext Context) {
Thread.Sleep(5 * 60 * 1000);
}

}

What's wrong on this code that AddOnBeginRequestAsync uses threads from same
thread pool as is used for serving other ASP.NET requests ?
All suggestions how to write HTTPModule asynchronously are welcome :-).

Many thanks.
Oct 27 '07 #1
3 4725
I've resolved it by not invoking via delegate but calling thread not from
worker thread pool. But I had to implement IAsyncResult to do it - is there
other easier way how to call some method asynchronously (and not using worker
process thread pool) without implementing IAsyncResult ?

Thank you.

"John" wrote:
Hi,

I need to write asynchronous HTTPModule which will sometimes execute long
job. I've written it using AddOnBeginRequestAsync but it still executes
synchronously - I am checking performance counters but after running X
requests which executes this "asynchronous" module all other requests go to
application queue - so it executes synchronously.

Code is based on the following article
http://msdn.microsoft.com/msdnmag/is...WickedCode/#S3

This is my sample code

public class RequestDelayModule : BaseHTTPModule {

protected override void Init() {
base.Init();
this.Application.AddOnBeginRequestAsync(new
BeginEventHandler(BeginRequest_AsyncBegin), new
EndEventHandler(BeginRequest_AsyncEnd));
return;
}

delegate void ABR(HttpContext Context);

IAsyncResult BeginRequest_AsyncBegin(object sender, EventArgs e,
AsyncCallback cb, object state) {
return new ABR(Application_BeginRequest).BeginInvoke(null, cb,
this.Context);
}

void BeginRequest_AsyncEnd(IAsyncResult ar) {
return;
}

void Application_BeginRequest(HttpContext Context) {
Thread.Sleep(5 * 60 * 1000);
}

}

What's wrong on this code that AddOnBeginRequestAsync uses threads from same
thread pool as is used for serving other ASP.NET requests ?
All suggestions how to write HTTPModule asynchronously are welcome :-).

Many thanks.
Oct 27 '07 #2
Hi John,

Yes, as you've found .NET Asynchornous method invoking through
Delegate.BeginInvoke also pickup thread from .NET CLR threadpool. So for
ASP.NET Async HttpHandler or Async page, you should not use it. Actually,
there does exist some asynchronous execution(such as the webservice
webrequest's async operation) which doesn't consume CLR threadpool. Here is
a good web article which has mentioned this:

#Async Pages in ASP.NET 2.0 - some results
http://www.pluralsight.com/blogs/fri...0/19/2892.aspx

Anyway, I suggest you always test the result when you try directly use the
existing async execution operations in ASP.NET async page to ensure that
does help on threadpool threads(If you do not implement your own async
pattern).

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
>From: =?Utf-8?B?Sm9obg==?= <aa****@nospam.nospam>
References: <77**********************************@microsoft.co m>
Subject: RE: Asynchronous HTTPModule executes synchronously ?
Date: Sat, 27 Oct 2007 13:11:02 -0700
>
I've resolved it by not invoking via delegate but calling thread not from
worker thread pool. But I had to implement IAsyncResult to do it - is
there
>other easier way how to call some method asynchronously (and not using
worker
>process thread pool) without implementing IAsyncResult ?

Thank you.

"John" wrote:
>Hi,

I need to write asynchronous HTTPModule which will sometimes execute
long
>job. I've written it using AddOnBeginRequestAsync but it still executes
synchronously - I am checking performance counters but after running X
requests which executes this "asynchronous" module all other requests go
to
>application queue - so it executes synchronously.

Code is based on the following article
http://msdn.microsoft.com/msdnmag/is...WickedCode/#S3

This is my sample code

public class RequestDelayModule : BaseHTTPModule {

protected override void Init() {
base.Init();
this.Application.AddOnBeginRequestAsync(new
BeginEventHandler(BeginRequest_AsyncBegin), new
EndEventHandler(BeginRequest_AsyncEnd));
return;
}

delegate void ABR(HttpContext Context);

IAsyncResult BeginRequest_AsyncBegin(object sender, EventArgs e,
AsyncCallback cb, object state) {
return new ABR(Application_BeginRequest).BeginInvoke(null, cb,
this.Context);
}

void BeginRequest_AsyncEnd(IAsyncResult ar) {
return;
}

void Application_BeginRequest(HttpContext Context) {
Thread.Sleep(5 * 60 * 1000);
}

}

What's wrong on this code that AddOnBeginRequestAsync uses threads from
same
>thread pool as is used for serving other ASP.NET requests ?
All suggestions how to write HTTPModule asynchronously are welcome :-).

Many thanks.
Oct 29 '07 #3
Hi John,

Have you got any further ideas on this? If there is any other questions on
this ,please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: st*****@online.microsoft.com (Steven Cheng[MSFT])
Organization: Microsoft
Date: Mon, 29 Oct 2007 02:40:54 GMT
Subject: RE: Asynchronous HTTPModule executes synchronously ?
>>
Hi John,

Yes, as you've found .NET Asynchornous method invoking through
Delegate.BeginInvoke also pickup thread from .NET CLR threadpool. So for
ASP.NET Async HttpHandler or Async page, you should not use it. Actually,
there does exist some asynchronous execution(such as the webservice
webrequest's async operation) which doesn't consume CLR threadpool. Here
is
>a good web article which has mentioned this:

#Async Pages in ASP.NET 2.0 - some results
http://www.pluralsight.com/blogs/fri...0/19/2892.aspx

Anyway, I suggest you always test the result when you try directly use the
existing async execution operations in ASP.NET async page to ensure that
does help on threadpool threads(If you do not implement your own async
pattern).

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.


Nov 1 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ollie Riches | last post by:
I have managed to get asycnhronous logging work for an asp.net application and I wanted some clarification on the method. Normally if the application is logging synchronously it has all the...
2
by: Darryl A. J. Staflund | last post by:
Hi there, Can anyone tell me why invoking a single SQL insert statement (well, rather, a method that performs a SQL insert) using an asynchronous delegate should result in twice the number of...
4
by: Michael C | last post by:
Hi all, Is there an easy way to get the parameters of an asynchronous delegate call from the callback function? Here's an example of what I'm trying to do: private delegate ArrayList...
3
by: Thomas Nielsen | last post by:
Hi, I need to make a web page that wait for 3 asynchronous processes to finish. So I am considering these options 1) Poll the status of the processes from the web page using the "REFRESH"...
3
by: Al | last post by:
Hi, I believe that when an event is Raised is C#, it is performed synchronously, as a value is returned by the event handler, even if that value is NULL. However, as VB does not have the ability...
1
by: kkao77 | last post by:
Someone help me please. I've tried to write an asynchronous method, but it didn't call my web service, do I need to do something in my webservice project to make it work? or if there is...
10
by: Susan | last post by:
I have a process that takes a while to run so I have it running asynchronously so that the user can continue working. My question is that I want to killl the process if the user changes the search...
1
by: keksy | last post by:
Hi every1, I am writing a small client/server application and in it I want to send an image asynchronous from the client to the server through a TCP socket. I found an example code on the MSDN...
0
by: =?Utf-8?B?aWFtc2Rr?= | last post by:
I have a windows client that calls web service 1 (Broker) synchronously, web service 1 then calls web service 2 (Service) asynchronously, web service 2 sleeps its thread for 10 seconds. When I put...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.