views:

53

answers:

2

I have a simple application that contains one button to be clicked in order to start logging, and basically I log messages to database. The application is already set up to log messages to a database. So, I tried to run my application in my machine but with two different browsers, for example( google chrome and Internet Explorer) at the same time. And i click the button from both browsers, but the strange thing is the threadID is the same for both browsers. However, when I run the application on same browser several times it does give a new threadID each time I execute it. WHY? As I was expecting the threadID to be different when i run the app from different browsers simultaneously since the execution time was different.

+5  A: 

The ThreadID has nothing to do with the browser; it has to do with the Thread running the server code. That is to say, the aspnet worker process (or whatever is running the piece of code you're logging from).

Noon Silk
okay.. basically what i did is to run the application with google chrome and then without closing that one i run the application with IE. and then i click the button from one browser after another but the threadId stays the same. So basically, should i understand what you are saying as "as long as i am running the application from the same machine it will run the same thread despite the different execution time." (note: I will google the aspnet worker process i havent heard it before)
Precious
@Precious: as soon as the server request has completed (this will happen before the browser completely displaying the results) it is free to serve another request. A new thread will be used as soon as there are concurrent requesting being processed by the server (however few or many different clients there are, over however many machines).
Richard
@Richard. Thanks for the clarification.
Precious
A: 

The server reuses threads to handle incoming requests (regardless of what browser you're using, what computer you're logging in with, etc.). I could point my browser at your server, and get the same ThreadId's as you're seeing. There's no guarantee (as far as I know) that your code will run on different threads across multiple requests. There's also no guarantee (as far as I know) that your code will run on the same thread across multiple requests.

Pwninstein
@Pwninstein thanks for clarification
Precious
Not a problem! :)
Pwninstein