Tech Off Thread

5 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Application settings not sticking

Back to Forum: Tech Off
  • User profile image
    W3bbo

    'lo

    As readers of my previous thread will remember, I managed to solve the date-format issue by overriding the Current Thread's culture information.

    However, this isn't of much use when you consider ASP.NET apps are multi-threaded.

    So after a bit of hackery, my Global.asax.cs looks like this:

    private Globalization.CultureInfo CI;
    
    void Application_Start(Object sender, EventArgs e) {
    
    //snip
    
            ' Set dates to ISO 8601 format
            CI = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
            
            CI.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Monday;
            CI.DateTimeFormat.FullDateTimePattern = "yyyy-MM-dd HH:mm";
            CI.DateTimeFormat.DateSeparator = "-";
            CI.DateTimeFormat.TimeSeparator = ":";
            CI.DateTimeFormat.LongDatePattern = "yyyy-MM-dd";
            CI.DateTimeFormat.LongTimePattern = "HH:mm";
            CI.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd";
            CI.DateTimeFormat.ShortTimePattern = "HH:mm";
            
            Threading.Thread.CurrentThread.CurrentCulture = CI;
    
    }
    
    void Application_BeginRequest(Object sender, EventArgs e) {
            if
    (Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.FullDateTimePattern
    <> "yyyy-MM-dd HH:mm") {
    
            
            
    
            
            Threading.Thread.CurrentThread.CurrentCulture = CI;
    
            
            
            
    }
    


    Whereupon in the BeginRequest method, "CI" is reporedtly Null.

    Whyso?

    And is there a better way to ensure all threads spawned after the initial thread have "CI" as their CultureInfo?

  • User profile image
    blowdart

    W3bbo wrote:

    Whereupon in the BeginRequest method, "CI" is reporedtly Null.

    Whyso?


    Because you're assuming the application spawns threads per request. Not true, the pipeline and page handler does.

    So, _BeginRequest is the only place to set it.

  • User profile image
    W3bbo

    blowdart wrote:
    W3bbo wrote:
    Whereupon in the BeginRequest method, "CI" is reporedtly Null.

    Whyso?


    Because you're assuming the application spawns threads per request. Not true, the pipeline and page handler does.

    So, _BeginRequest is the only place to set it.


    True.

    But I found the problem, its to do with Application.asax pooling. So I set "CI" to static and it works.

  • User profile image
    Minh

    What does Application.asax pooling involve?

  • User profile image
    bitmask

    Minh wrote:
    What does Application.asax pooling involve?


    There are multiple instances of the HttpApplication derived class in global.asax. The runtime creates an instance to associate with each request thread: http://odetocode.com/Articles/89.aspx

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.