麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

.NET4.5可以給所有線程設置默認的Culture了

2019-11-17 01:29:38
字體:
來源:轉載
供稿:網友

.NET4.5可以給所有線程設置默認的Culture了

How to set CurrentCulture for all threads in a domain in .NET 4.5

Before .NET 4.5 if we wanted to set CurrentCulture for the current thread, we would need to set the culture in somewhere like application bootstrap.

For example in the following code we set the culture to en-us:

線程默認的是用服務器的Cultrue

.NET4.5之前,只能用以下代碼只能針對單個線程,如果每次執行線程都要重新設置一下。。。

Syste
m.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");

For single threaded application and for regular usages, the PReceding code works fine and there is nothing to be worry about. But problems come to the surface if we are working on a multi-threaded application which needs to have more than one thread.

Basically in .NET platform thread culture is read from Windows system culture by default and if the system culture is different from application culture, you need to somehow set the thread's culture manually for every threads.

The same problem is even there for Tasks in Task Parallel Library which means task's Operations are done in the context of the Windows system thread by default. So we need to set the current culture manually inside of each task if we are doing something relevant to localization and so on.

Fortunately in .NET 4.5 a couple of cool properties have been added to the CultureInfo class called DefaultThreadCurrentCulture and DefaultThreadCurrentUICulture. A default culture will be set to the whole domain and for all threads by assigning a culture to these properties in application bootstrap.

.NET4.5就簡單了,在網站啟動的時候 ,設置一下這個,所有線程都會用這個默認的Culture了!

System.Globalization.CultureInfo.DefaultThreadCurrentCulture = new System.Globalization.CultureInfo("en-US");System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = new System.Globalization.CultureInfo("en-US");
[assembly: System.Web.PreApplicationStartMethod(typeof(Web.AppStart), "Main")]namespace Web{        public class AppStart    {        public static void Main()        {            //set default culture here                  }    }}

Have fun!


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 毛片视频网站 | 国产免费人做人爱午夜视频 | 一区二区三区小视频 | 中文字幕天堂在线 | 秋霞a级毛片在线看 | 91成人天堂久久成人 | 海角在线观看91一区二区 | 国产99久久精品一区二区 | 天堂成人国产精品一区 | 性插视频 | 亚洲人成在线播放网站 | 欧美黄色一级片在线观看 | 久久男人的天堂 | 99精品视频在线免费观看 | 中国国语毛片免费观看视频 | 黄色网址在线视频 | 欧美黄成人免费网站大全 | 中国久久久 | 成人在线网站 | 国产一级在线看 | 国产成人精品视频在线 | 污片视频在线观看 | 91九色精品 | 中文在线观看www | 国产免费观看a大片的网站 欧美成人一级 | 久久精品视频日本 | 午夜在线视频观看 | 国产色视频一区 | 高清做爰免费无遮网站挡 | av在线等 | 5xsq在线视频 | 亚洲av一级毛片特黄大片 | 日韩精品一二三区 | 成人在线视频免费播放 | 羞羞答答xxdd在线播放 | 神马久久蜜桃 | 一区二区三区视频播放 | 久久久电影电视剧免费看 | 亚洲国产精品久久久久久久久久久 | 港台三级在线观看 | 天天夜碰日日摸日日澡性色av |