Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

c# - Will a request in IIS run on a single thread?

We have a system that runs in IIS.

The system should always run using the same "culture", but we cannot rely on the server settings being set correct.

One way to do it is to specify the culture everytime we do a ToString.

However, we were wondering, is it possible to set the culture on a thread at the begining of a method and rely on all the code in that method being run on the same thread?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No. ASP.NET exhibits thread agility - in some situations, the request may move from one thread to another at specific points in its request lifecycle. (It's not "just anywhere"; this blog post gives more specific details.)

Unfortunately this isn't as clearly documented as it might be, and it's relatively hard to provoke - so you can easily get into the situation where under test loads, all is fine - but in production things go wrong.

However, some tests I ran a while ago (look for "jskeet" within the page) suggests that Thread.CurrentCulture is preserved even when thread agility kicks in.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...