Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...