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. General Programming
  3. C#
  4. Problem to remove temporary image files once used

Problem to remove temporary image files once used

Scheduled Pinned Locked Moved C#
helpgraphics
5 Posts 3 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.
  • V Offline
    V Offline
    VCsamir
    wrote on last edited by
    #1

    hi friends, seniors $ all, I have a form on which i am using layout panel. on this layout panel i am adding user control during runtime. the control consists of a picturebox and label. the image which is displayed on picture box is copied from the source folder to temp folder. this image is resized and bitmap is created and passed to picture box. now i want to clear the temporary moved files, which is not happening.. :( i get the file is in use. so i disposed the child form, before comming to parent form. even clearing the layout panel didint help.. friends please suggest me some help regards Samir

    H L 2 Replies Last reply
    0
    • V VCsamir

      hi friends, seniors $ all, I have a form on which i am using layout panel. on this layout panel i am adding user control during runtime. the control consists of a picturebox and label. the image which is displayed on picture box is copied from the source folder to temp folder. this image is resized and bitmap is created and passed to picture box. now i want to clear the temporary moved files, which is not happening.. :( i get the file is in use. so i disposed the child form, before comming to parent form. even clearing the layout panel didint help.. friends please suggest me some help regards Samir

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      Which of the many available Methods are you using to load the bitmap? I suspect that you are using Image.FromFile() as this is a well documented problem with this method. If that is correct then switch to Image.FromStream() (look it up). Hopefully this will resolve your problems.

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      V 1 Reply Last reply
      0
      • H Henry Minute

        Which of the many available Methods are you using to load the bitmap? I suspect that you are using Image.FromFile() as this is a well documented problem with this method. If that is correct then switch to Image.FromStream() (look it up). Hopefully this will resolve your problems.

        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

        V Offline
        V Offline
        VCsamir
        wrote on last edited by
        #3

        hi sir, i am using filestream only.. one more thing i am using thread to load the controls inside layout panel regards samir

        H 1 Reply Last reply
        0
        • V VCsamir

          hi sir, i am using filestream only.. one more thing i am using thread to load the controls inside layout panel regards samir

          H Offline
          H Offline
          Henry Minute
          wrote on last edited by
          #4

          In that case, without seeing any code, is there a possibility that the threads are terminating before properly closing the streams?

          Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

          1 Reply Last reply
          0
          • V VCsamir

            hi friends, seniors $ all, I have a form on which i am using layout panel. on this layout panel i am adding user control during runtime. the control consists of a picturebox and label. the image which is displayed on picture box is copied from the source folder to temp folder. this image is resized and bitmap is created and passed to picture box. now i want to clear the temporary moved files, which is not happening.. :( i get the file is in use. so i disposed the child form, before comming to parent form. even clearing the layout panel didint help.. friends please suggest me some help regards Samir

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            In order to be able to delete a file, everything that points to the file must have been disposed. Candidates are: Image.FromFile, Image.FromStream, PictureBox.ImageLocation The problem here is you have to do special things at the end of the PictureBox's life; if the image is used in more than one location in your code, it may be hard to correctly decide on its disposal. There also is a different approach, where the problem is avoided beforehand, by copying the image; this is a schematic example:

            Image image1=Image.FromFile(...);
            Bitmap bitmap1=new Bitmap(image1);        // bitmap1 is unrelated to the file!
            image1.Dispose();                         // now the file is deletable
            PictureBox.Image=bitmap1;
            ...
            myForm.Close();                           // will lead to PictureBox disposal
            // bitmap1 will be garbage collected at some point, this does not affect the file
            

            :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

            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