Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Delete Temp File after N seconds

Delete Temp File after N seconds

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netbusinesshelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shawn_H
    wrote on last edited by
    #1

    Im using ASP.net 2.0. I have a need to temporarily save an image to disk, and then want it automatically deleted within a minute. Im a gernating dynamic pdfs, with dynamic charts embeded in the PDF. The charts need to be temporarily saved as an image on disk with Guid.NewGuid().ToString() + ".jpg"; for example as the file name. I thought about using the Web.Cache with a Delegate CacheItemRemoveCallBack setting abosulte expiration to expire in 60 seconds, then when the listener is fired, delete the file. Problem is, that method will not work. because the file has a unique key in cache (using the file name as the cache key which is from NewGuid) , it will never be fired beacause that cache key will never be fired again. the same image will never be generated twice. For time-based dependencies, the callback is not fired when the time is up, but rather the next time the cached item is accessed. So cant depend on these to act as a timer for me to remove an item in N seconds. I would rather not get into the business of schedule task manager to run and delete files etc... I suppose that in this handler (btw, its in an httpHandler) I could just do a check on time stamps and remove files older than N secs, I would rather not slow the request down though. For some reason, im thinking Threading namspace / Timer object (maybe overboard). Does anyone have any suggestions? let me know if you need more info. Thank You all greatly in advance Shawn

    B 1 Reply Last reply
    0
    • S Shawn_H

      Im using ASP.net 2.0. I have a need to temporarily save an image to disk, and then want it automatically deleted within a minute. Im a gernating dynamic pdfs, with dynamic charts embeded in the PDF. The charts need to be temporarily saved as an image on disk with Guid.NewGuid().ToString() + ".jpg"; for example as the file name. I thought about using the Web.Cache with a Delegate CacheItemRemoveCallBack setting abosulte expiration to expire in 60 seconds, then when the listener is fired, delete the file. Problem is, that method will not work. because the file has a unique key in cache (using the file name as the cache key which is from NewGuid) , it will never be fired beacause that cache key will never be fired again. the same image will never be generated twice. For time-based dependencies, the callback is not fired when the time is up, but rather the next time the cached item is accessed. So cant depend on these to act as a timer for me to remove an item in N seconds. I would rather not get into the business of schedule task manager to run and delete files etc... I suppose that in this handler (btw, its in an httpHandler) I could just do a check on time stamps and remove files older than N secs, I would rather not slow the request down though. For some reason, im thinking Threading namspace / Timer object (maybe overboard). Does anyone have any suggestions? let me know if you need more info. Thank You all greatly in advance Shawn

      B Offline
      B Offline
      Bassam Saoud
      wrote on last edited by
      #2

      Why not use a Windows Service that will delete periodically?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups