473,386 Members | 1,846 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,386 software developers and data experts.

IHttpModule Event Threading

What gaurantees are there in the way of which thread the events are called from.

I've seen:
Thread A Begin
Thread B Begin
Thread A End
Thread A End

That seems to indicate that Begin and End can't be assumed to be called from the same thread, but can I assume that the Begin will happen on the same thread that executes the request?

I'm trying to use these events to log which thread is executing a request.

Furthermore, I'm trying to do the same thing with a SOAP extension. Would anyone know the answer or should I ask in the other forums?

Thanks,
Andrew Lippitt
Nov 18 '05 #1
5 2349
"Andrew Lippitt" <Andrew Li*****@discussions.microsoft.com> wrote in message
news:A1**********************************@microsof t.com...
What gaurantees are there in the way of which thread the events are called from.
I've seen:
Thread A Begin
Thread B Begin
Thread A End
Thread A End

That seems to indicate that Begin and End can't be assumed to be called from the same thread, but can I assume that the Begin will happen on the
same thread that executes the request?
I'm trying to use these events to log which thread is executing a request.

Furthermore, I'm trying to do the same thing with a SOAP extension. Would

anyone know the answer or should I ask in the other forums?

In general, you can make no assumption about the order in which threads
execute.

Now, in this case, you'll need to be more specific about what you mean by
"Begin" and "End". The IHttpModule interface doesn't define any events.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #2
Thanks for the quick reply!

I'll try to elaborate. I'm implementing IHttpModule in an attempt to trap the BeginRequest and EndRequest events that the HttpApplication interface it provides exposes. My goal is to use these events to write a log indicating which pages were executed on which threads.

What I need to know is what I can rely upon in terms of which thread these events will be fired from.

It seems that the normal case is that EndRequest is fired from the same thread that BeginRequest is. However, the following sample will demonstrate this is not always the case. When this is installed, firing off several requests simultaneously will sometimes cause the BeginRequest and EndRequest for a single request to be fired from two different threads.

I'd expect for example that if two requests happen simultaneously that two different threads would service them and I'd get something like:

Thread 1: BeginRequest
Thread 2: BeginRequest
Thread 1: EndRequest
Thread 2: EndRequest

What happens in the case that seems odd is that I'll get more along the lines of

Thread 1: BeginRequest
Thread 2: BeginRequest
Thread 1: EndRequest
Thread 1: EndRequest

My question is what CAN I assume about the threads that call these events and how they relate to the thread that is actually going to service the request. And by servicing the request, I mean can I assume that the thread that fires BeginRequest will be the thread that executes the System.Web.UI.Page that was requested?

using System;
using System.Web;

public class HttpEvents : IHttpModule
{
public void Init(HttpApplication _context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
context.EndRequest += new EventHandler(context_EndRequest);
}

private void context_BeginRequest(object sender, EventArgs e)
{
System.Diagnostics.Trace.WriteLine("Thread " + System.Threading.Thread.CurrentThread.GetHashCode( ) + ": BeginRequest");
}

private void context_EndRequest(object sender, EventArgs e)
{
System.Diagnostics.Trace.WriteLine("Thread " + System.Threading.Thread.CurrentThread.GetHashCode( ) + ": EndRequest");
}
}


"John Saunders" wrote:
"Andrew Lippitt" <Andrew Li*****@discussions.microsoft.com> wrote in message
news:A1**********************************@microsof t.com...
What gaurantees are there in the way of which thread the events are called

from.

I've seen:
Thread A Begin
Thread B Begin
Thread A End
Thread A End

That seems to indicate that Begin and End can't be assumed to be called

from the same thread, but can I assume that the Begin will happen on the
same thread that executes the request?

I'm trying to use these events to log which thread is executing a request.

Furthermore, I'm trying to do the same thing with a SOAP extension. Would

anyone know the answer or should I ask in the other forums?

In general, you can make no assumption about the order in which threads
execute.

Now, in this case, you'll need to be more specific about what you mean by
"Begin" and "End". The IHttpModule interface doesn't define any events.
--
John Saunders
johnwsaundersiii at hotmail

Nov 18 '05 #3
Hi Andrew:

I've never found a guarantee that a request will be on the same thread
for the entire processing pipeline.

--
Scott
http://www.OdeToCode.com

On Mon, 5 Jul 2004 13:31:01 -0700, "Andrew Lippitt"
<An***********@discussions.microsoft.com> wrote:
Thanks for the quick reply!

I'll try to elaborate. I'm implementing IHttpModule in an attempt to trap the BeginRequest and EndRequest events that the HttpApplication interface it provides exposes. My goal is to use these events to write a log indicating which pages were executed on which threads.


Nov 18 '05 #4
Hi,

After HttpApplication.InitInternal set all required events that should
be execute by application, HttpApplication.ResumeSteps actually perform
them. Now if you use any reflection tool you will see that ResumeSteps
guarantee that all execute steps occurred in the same thread
(this.OnThreadEnter(); and this.OnThreadLeave();).
(You can look at my blog for full request pipeline desc. :
http://weblogs.asp.net/ngur/archive/...05/173301.aspx)

Anyway correct me if I wrong but I think you record the thread that
deals with the context event and not the thread that perform request
pipeline.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)52-8888377
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #5
"Andrew Lippitt" <An***********@discussions.microsoft.com> wrote in message
news:95**********************************@microsof t.com...
Thanks for the quick reply!

I'll try to elaborate. I'm implementing IHttpModule in an attempt to trap the BeginRequest and EndRequest events that the HttpApplication interface it
provides exposes. My goal is to use these events to write a log indicating
which pages were executed on which threads.
What I need to know is what I can rely upon in terms of which thread these

events will be fired from.

You can't rely on anything at all. That's my point.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #6

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

Similar topics

0
by: moid | last post by:
Sir we are implementing front controller in asp.net. we implement three event-handler 1. PreRequestHandlerExecute 2. PostRequestHandlerExecute 3. BeginRequest we just want to initialize...
4
by: Mike | last post by:
I've created a custom IHttpModule that does custom authentication. Currently it stores authenticated user info in a hashtable within the class so I don't have to re-authenticate against a database...
6
by: Andy G | last post by:
I am trying to implement the global error handling described on this page... http://www.dotnetdevs.com/articles/GlobalErrorHandling.aspx I'm a VB person and don't understand much of C# when it...
6
by: Simone Busoli | last post by:
Hello, I am trying to understand when IHttpModule.Dispose method is called. Is it called when the Application is disposed, or when the request ends? If I want to make an object Application-wide...
5
by: Richard | last post by:
I've developed a small ASPX template framework (based on Chun Li's article on CodeProject: http://www.codeproject.com/aspnet/headerfooter.asp#xx849313xx) which uses a IHttpModule to apply...
0
by: John | last post by:
I am writing a custom httpmodule, I can catch BeginRequest, EndRequest event, But I can not catch Error event, I tried throwing an error from my Web Service, creating a security exception (by...
3
by: trullock | last post by:
Hi, Ive written a URLRewriter IHttpModule which all works fine. I've come to make a change to it which involves deciding where to redirect based on what role a user is in....
1
by: Eric Goforth | last post by:
Hello, I'm trying to create an Http Helper Module in VS.NET 2005. When I do the following the .NET ide complains that it doesn't know what the IHttpModule type is. I initially tried it without...
1
by: Eric Goforth | last post by:
Hello, I found a C# example on the web that used an httpmodule. I've translated it to VB.NET and the website compiles fine, but when I build the website the iHttpModule doesn't compile, I can't...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.