locked
Application Start in Debug Mode / Local Computer RRS feed

  • Question

  • User-1188570427 posted

    I am doing the below code based on 2 minutes. 

    Will this code cause Application_Start to fire each time this code is hit?  So every 2 minutes I should see Application_Start fire? Or am I seeing this just because I am in debug mode?  I'm writing a log to my local C Drive and I want to do a count when another cache is expired, but it keeps resetting to 0 ?

                    HttpContext.Current.Cache.Add(
                        DummyCacheItemKey, 
                        DummyCacheItemValue, 
                        null,
                        DateTime.Now.AddMinutes(2), 
                        Cache.NoSlidingExpiration, 
                        CacheItemPriority.NotRemovable,
                        new CacheItemRemovedCallback(CacheItemRemovedCallback)
                        );

    Saturday, February 7, 2015 2:25 PM

Answers

  • User-1188570427 posted

    I have NO idea what was changed or if I even changed anything.  I just added a  line of code:

    RecordNumber = RecordNumber + 1;

    compared to:

    RecordNumber++;

    Now it seems to be working like I expected and does not hit the application_start every time etc.

    Here are the logs:

    ****************  Delete Lock File Time: 2/9/2015 4:45:41 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
                                      Application_Start... Time: 2/9/2015 4:45:41 AM
    
    
    ****************  Start Record #: 0
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 4:48:01 AM  ]]]]  ****************
    ****************  Resetting the cache... Time: 2/9/2015 4:45:42 AM
    ****************  Resetting the cache... Time: 2/9/2015 4:45:42 AM
     ----------------------------------------------------------------------------------------------------------- 
    
    ****************  RecordNumber: 1
    
    ****************  Create Lock File Time: 2/9/2015 4:48:00 AM
    
    ****************  Start Do Stuff Time: 2/9/2015 4:48:00 AM
    
    
    ****************  End Do Stuff Time: 2/9/2015 4:48:00 AM
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 4:50:20 AM  ]]]]  ****************
    
    ****************  Delete Lock File Time: 2/9/2015 4:48:00 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
    ****************  Resetting the cache... Time: 2/9/2015 4:48:00 AM
     ----------------------------------------------------------------------------------------------------------- 
    
    ****************  RecordNumber: 1
    
    ****************  Create Lock File Time: 2/9/2015 4:50:20 AM
    
    ****************  Start Do Stuff Time: 2/9/2015 4:50:20 AM
    
    
    ****************  End Do Stuff Time: 2/9/2015 4:50:20 AM
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 4:52:40 AM  ]]]]  ****************
    
    ****************  Delete Lock File Time: 2/9/2015 4:50:20 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
    ****************  Resetting the cache... Time: 2/9/2015 4:50:20 AM
     ----------------------------------------------------------------------------------------------------------- 
    
    ****************  RecordNumber: 2
    
    ****************  Create Lock File Time: 2/9/2015 4:52:20 AM
    
    ****************  Start Do Stuff Time: 2/9/2015 4:52:20 AM
    
    
    ****************  End Do Stuff Time: 2/9/2015 4:52:20 AM
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 4:54:40 AM  ]]]]  ****************
    
    ****************  Delete Lock File Time: 2/9/2015 4:52:20 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
    ****************  Resetting the cache... Time: 2/9/2015 4:52:20 AM
     ----------------------------------------------------------------------------------------------------------- 
    
    ****************  RecordNumber: 3
    
    ****************  Create Lock File Time: 2/9/2015 4:54:20 AM
    
    ****************  Start Do Stuff Time: 2/9/2015 4:54:20 AM
    
    
    ****************  End Do Stuff Time: 2/9/2015 4:54:20 AM
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 4:56:40 AM  ]]]]  ****************
    
    ****************  Delete Lock File Time: 2/9/2015 4:54:20 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
    ****************  Resetting the cache... Time: 2/9/2015 4:54:20 AM
     ----------------------------------------------------------------------------------------------------------- 
    
    ****************  RecordNumber: 4
    
    ****************  Create Lock File Time: 2/9/2015 4:56:20 AM
    
    ****************  Start Do Stuff Time: 2/9/2015 4:56:20 AM
    
    
    ****************  End Do Stuff Time: 2/9/2015 4:56:20 AM
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 4:58:40 AM  ]]]]  ****************
    
    ****************  Delete Lock File Time: 2/9/2015 4:56:20 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
    ****************  Resetting the cache... Time: 2/9/2015 4:56:20 AM
     ----------------------------------------------------------------------------------------------------------- 
    
    ****************  RecordNumber: 5
    
    ****************  Create Lock File Time: 2/9/2015 4:58:20 AM
    
    ****************  Start Do Stuff Time: 2/9/2015 4:58:20 AM
    
    
    ****************  End Do Stuff Time: 2/9/2015 4:58:20 AM
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 5:00:40 AM  ]]]]  ****************
    
    ****************  Delete Lock File Time: 2/9/2015 4:58:20 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
    ****************  Resetting the cache... Time: 2/9/2015 4:58:20 AM
     ----------------------------------------------------------------------------------------------------------- 
    
    ****************  RecordNumber: 6
    
    ****************  Create Lock File Time: 2/9/2015 5:00:20 AM
    
    ****************  Start Do Stuff Time: 2/9/2015 5:00:20 AM
    
    
    ****************  End Do Stuff Time: 2/9/2015 5:00:20 AM
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 5:02:40 AM  ]]]]  ****************
    
    ****************  Delete Lock File Time: 2/9/2015 5:00:20 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
    ****************  Resetting the cache... Time: 2/9/2015 5:00:20 AM
     ----------------------------------------------------------------------------------------------------------- 
    
    ****************  RecordNumber: 7
    
    ****************  Create Lock File Time: 2/9/2015 5:02:20 AM
    
    ****************  Start Do Stuff Time: 2/9/2015 5:02:20 AM
    
    
    ****************  End Do Stuff Time: 2/9/2015 5:02:20 AM
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 5:04:40 AM  ]]]]  ****************
    
    ****************  Delete Lock File Time: 2/9/2015 5:02:20 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
    ****************  Resetting the cache... Time: 2/9/2015 5:02:20 AM
     ----------------------------------------------------------------------------------------------------------- 
    
    ****************  RecordNumber: 8
    
    ****************  Create Lock File Time: 2/9/2015 5:04:20 AM
    
    ****************  Start Do Stuff Time: 2/9/2015 5:04:20 AM
    
    
    ****************  End Do Stuff Time: 2/9/2015 5:04:20 AM
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 5:06:40 AM  ]]]]  ****************
    
    ****************  Delete Lock File Time: 2/9/2015 5:04:20 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
    ****************  Resetting the cache... Time: 2/9/2015 5:04:20 AM
     ----------------------------------------------------------------------------------------------------------- 
    
    ****************  RecordNumber: 9
    
    ****************  Create Lock File Time: 2/9/2015 5:06:20 AM
    
    ****************  Start Do Stuff Time: 2/9/2015 5:06:20 AM
    
    
    ****************  End Do Stuff Time: 2/9/2015 5:06:20 AM
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 5:08:40 AM  ]]]]  ****************
    
    ****************  Delete Lock File Time: 2/9/2015 5:06:20 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
    ****************  Resetting the cache... Time: 2/9/2015 5:06:20 AM
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 9, 2015 6:05 AM

All replies

  • User-271186128 posted

    Hi tvb2727,

    As far as I know, the Application_Start event is fired once when the application domain is loaded. If you see it firing more than once then this would mean that the application restarts.

    You could refer to this link: application_start event called multiple times in MVC application

    Best Regards,
    Dillion

    Monday, February 9, 2015 2:47 AM
  • User-1188570427 posted

    Hi tvb2727,

    As far as I know, the Application_Start event is fired once when the application domain is loaded. If you see it firing more than once then this would mean that the application restarts.

    You could refer to this link: application_start event called multiple times in MVC application

    Best Regards,
    Dillion

    Yea, I guess my Application_Start is not being restarted, but my private int RecordNumber keeps being reset to 0?  I am trying to count how many times a certain section of code is called and add 1 to the RecordNumber, but somehow it is being reset to 0.

            private int RecordNumber = 0;
    
            protected void Application_Start(object sender, EventArgs e)
            {
    
    ....
    
            }

    Monday, February 9, 2015 5:43 AM
  • User-1188570427 posted

    I have NO idea what was changed or if I even changed anything.  I just added a  line of code:

    RecordNumber = RecordNumber + 1;

    compared to:

    RecordNumber++;

    Now it seems to be working like I expected and does not hit the application_start every time etc.

    Here are the logs:

    ****************  Delete Lock File Time: 2/9/2015 4:45:41 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
                                      Application_Start... Time: 2/9/2015 4:45:41 AM
    
    
    ****************  Start Record #: 0
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 4:48:01 AM  ]]]]  ****************
    ****************  Resetting the cache... Time: 2/9/2015 4:45:42 AM
    ****************  Resetting the cache... Time: 2/9/2015 4:45:42 AM
     ----------------------------------------------------------------------------------------------------------- 
    
    ****************  RecordNumber: 1
    
    ****************  Create Lock File Time: 2/9/2015 4:48:00 AM
    
    ****************  Start Do Stuff Time: 2/9/2015 4:48:00 AM
    
    
    ****************  End Do Stuff Time: 2/9/2015 4:48:00 AM
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 4:50:20 AM  ]]]]  ****************
    
    ****************  Delete Lock File Time: 2/9/2015 4:48:00 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
    ****************  Resetting the cache... Time: 2/9/2015 4:48:00 AM
     ----------------------------------------------------------------------------------------------------------- 
    
    ****************  RecordNumber: 1
    
    ****************  Create Lock File Time: 2/9/2015 4:50:20 AM
    
    ****************  Start Do Stuff Time: 2/9/2015 4:50:20 AM
    
    
    ****************  End Do Stuff Time: 2/9/2015 4:50:20 AM
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 4:52:40 AM  ]]]]  ****************
    
    ****************  Delete Lock File Time: 2/9/2015 4:50:20 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
    ****************  Resetting the cache... Time: 2/9/2015 4:50:20 AM
     ----------------------------------------------------------------------------------------------------------- 
    
    ****************  RecordNumber: 2
    
    ****************  Create Lock File Time: 2/9/2015 4:52:20 AM
    
    ****************  Start Do Stuff Time: 2/9/2015 4:52:20 AM
    
    
    ****************  End Do Stuff Time: 2/9/2015 4:52:20 AM
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 4:54:40 AM  ]]]]  ****************
    
    ****************  Delete Lock File Time: 2/9/2015 4:52:20 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
    ****************  Resetting the cache... Time: 2/9/2015 4:52:20 AM
     ----------------------------------------------------------------------------------------------------------- 
    
    ****************  RecordNumber: 3
    
    ****************  Create Lock File Time: 2/9/2015 4:54:20 AM
    
    ****************  Start Do Stuff Time: 2/9/2015 4:54:20 AM
    
    
    ****************  End Do Stuff Time: 2/9/2015 4:54:20 AM
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 4:56:40 AM  ]]]]  ****************
    
    ****************  Delete Lock File Time: 2/9/2015 4:54:20 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
    ****************  Resetting the cache... Time: 2/9/2015 4:54:20 AM
     ----------------------------------------------------------------------------------------------------------- 
    
    ****************  RecordNumber: 4
    
    ****************  Create Lock File Time: 2/9/2015 4:56:20 AM
    
    ****************  Start Do Stuff Time: 2/9/2015 4:56:20 AM
    
    
    ****************  End Do Stuff Time: 2/9/2015 4:56:20 AM
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 4:58:40 AM  ]]]]  ****************
    
    ****************  Delete Lock File Time: 2/9/2015 4:56:20 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
    ****************  Resetting the cache... Time: 2/9/2015 4:56:20 AM
     ----------------------------------------------------------------------------------------------------------- 
    
    ****************  RecordNumber: 5
    
    ****************  Create Lock File Time: 2/9/2015 4:58:20 AM
    
    ****************  Start Do Stuff Time: 2/9/2015 4:58:20 AM
    
    
    ****************  End Do Stuff Time: 2/9/2015 4:58:20 AM
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 5:00:40 AM  ]]]]  ****************
    
    ****************  Delete Lock File Time: 2/9/2015 4:58:20 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
    ****************  Resetting the cache... Time: 2/9/2015 4:58:20 AM
     ----------------------------------------------------------------------------------------------------------- 
    
    ****************  RecordNumber: 6
    
    ****************  Create Lock File Time: 2/9/2015 5:00:20 AM
    
    ****************  Start Do Stuff Time: 2/9/2015 5:00:20 AM
    
    
    ****************  End Do Stuff Time: 2/9/2015 5:00:20 AM
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 5:02:40 AM  ]]]]  ****************
    
    ****************  Delete Lock File Time: 2/9/2015 5:00:20 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
    ****************  Resetting the cache... Time: 2/9/2015 5:00:20 AM
     ----------------------------------------------------------------------------------------------------------- 
    
    ****************  RecordNumber: 7
    
    ****************  Create Lock File Time: 2/9/2015 5:02:20 AM
    
    ****************  Start Do Stuff Time: 2/9/2015 5:02:20 AM
    
    
    ****************  End Do Stuff Time: 2/9/2015 5:02:20 AM
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 5:04:40 AM  ]]]]  ****************
    
    ****************  Delete Lock File Time: 2/9/2015 5:02:20 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
    ****************  Resetting the cache... Time: 2/9/2015 5:02:20 AM
     ----------------------------------------------------------------------------------------------------------- 
    
    ****************  RecordNumber: 8
    
    ****************  Create Lock File Time: 2/9/2015 5:04:20 AM
    
    ****************  Start Do Stuff Time: 2/9/2015 5:04:20 AM
    
    
    ****************  End Do Stuff Time: 2/9/2015 5:04:20 AM
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 5:06:40 AM  ]]]]  ****************
    
    ****************  Delete Lock File Time: 2/9/2015 5:04:20 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
    ****************  Resetting the cache... Time: 2/9/2015 5:04:20 AM
     ----------------------------------------------------------------------------------------------------------- 
    
    ****************  RecordNumber: 9
    
    ****************  Create Lock File Time: 2/9/2015 5:06:20 AM
    
    ****************  Start Do Stuff Time: 2/9/2015 5:06:20 AM
    
    
    ****************  End Do Stuff Time: 2/9/2015 5:06:20 AM
    
    ****************  [[[ About Next Service Run Time: 2/9/2015 5:08:40 AM  ]]]]  ****************
    
    ****************  Delete Lock File Time: 2/9/2015 5:06:20 AM
    
    ****************  DateTime Absolute Expiration: DateTime.Now.AddMinutes(2)
    
    ****************  Resetting the cache... Time: 2/9/2015 5:06:20 AM
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 9, 2015 6:05 AM