Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 441721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:00:02+00:00 2026-05-12T21:00:02+00:00

Simplest explanation I can produce: In my .NET1.1 web app I create a file

  • 0

Simplest explanation I can produce:

In my .NET1.1 web app I create a file on disc, in the Render method, and add an item to the Cache to expire within, say, a minute. I also have a callback method, to be called when the cache item expires, which deletes the file created by Render. In the Page_Init method I try to access the file which the Render method wrote to disc. Both these methods have a lock statement, locking a private static Object.

Intention:

To create a page which essentially writes a copy of itself to disc, which gets deleted before it gets too old (or out of date, content-wise), while serving the file if it exists on disc.

Problem observed:

This is really two issues, I think. Requesting the page does what I expect, it renders the page to disc and serves it immediately, while adding the expiry item to the cache. For testing the expiry time is 1 minute.

I then expect that the callback method will get called after 60 seconds and delete the file. It doesn’t.

After another minute (for the sake of argument) I refresh the page in the browser. Then I can see the callback method get called and place a lock on the lock object. The Page_Init also gets called and places a lock on the same object. However, both methods appear to enter their lock code block and proceed with execution.

This results in: Render checks file is there, callback method deletes file, render method tries to serve now-deleted-file.

Horribly simplified code extract:

public class MyPage : Page
{
  private static Object lockObject = new Obect();

  protected void Page_Init(...)
  {
    if (File.Exists(...))
    {
      lock (lockObject)
      {
        if (File.Exists(...))
        {
          Server.Transfer(...);
        }
      }
    }
  }

  protected override void Render(...)
  {
    If (!File.Exists(...))
    {
      // write file out and serve initial copy from memory
      Cache.Add(..., new CacheItemRemovedCallback(DoCacheItemRemovedCallback));
    }
  }

  private static void DoCacheItemRemovedCallback(...)
  {
    lock (lockObject)
    {
      If (File.Exists(...))
        File.Delete(...);
    }
  }
}

Can anyone explain this, please? I understand that the callback method is, essentially, lazy and therefore only calls back once I make a request, but surely the threading in .NET1.1 is good enough not to let two lock() blocks enter simultaneously?

Thanks,

Matt.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T21:00:03+00:00Added an answer on May 12, 2026 at 9:00 pm

    Not sure why your solution doesn’t work, but that might be a good thing, considering the consequences…

    I would suggest a completely different route. Separate the process of managing the file from the process of requesting the file.

    Requests should just go to the cache, get the full path of the file, and send it to the client.

    Another process (not bound to requests) is responsible for creating and updating the file. It simply creates the file on first use/access and stores the full path in the cache (set to never expire). At regular/appropriate intervals, it re-creates the file with a different, random name, sets this new path in the cache, and then deletes the old file (being careful that it isn’t locked by another request).

    You can spawn this file managing process on application startup using a thread or the ThreadPool. Linking your file management and requests will always cause you problems as your process will be run concurrently, requiring you to do some thread synchronization which is always best to avoid.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In it's simplest explanation, I'm making a really small interactive movie app on Android.
The simplest way to launch a web browser from within a blackberry app is:
The simplest example that I can provide for what I want to do is
This seems like the simplest Git question, but I can't find ANYTHING on it.
I have the simplest PhoneGap app one could imagine! All I'm trying to do
can anybody post the simplest possible example for django-ajax-selects ? Just one model with
Simplest case: You want to make a text file which says The MD5 hash
In its simplest form, my app displays 10 UIImageViews, each containing an image. Even
For VC, I can write a DEF file and use the 'NONAME' directive to
Simplest fool proof(?) method to check for string object I've seen. Tested with many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.