Click here to Skip to main content
15,909,737 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please guys i need a quick answer


i'm using in my application pictures that the user can delete from a specified folder .. i tried to made sure that no processes are using these pictures so i can delete them.. i searched for solution like using the dispatcher and GC (GC.WaitForPendingFinalizers();GC.Collect(); ).. but that didn't help..i'm still new in programming so i'm not sure i fully understand this process.. so i need a clear method..


each picture in my program is on a border's background using Border[i].Background = new ImageBrush(((ImageSource)(System.ComponentModel.TypeDescriptor.GetConverter(typeof(ImageSource)).ConvertFromInvariantString(@files[i]))));

files[i] contains the image's path



thanks in advance
Posted
Updated 28-Feb-12 23:58pm
v2
Comments
Nestor Arturo 27-Feb-12 15:46pm    
Very vague question... more details please.
R. Giskard Reventlov 27-Feb-12 15:47pm    
Hit them with a hammer. :-)
ZurdoDev 27-Feb-12 16:02pm    
That usually shatters them. He needs them disposed of.
Nestor Arturo 27-Feb-12 16:34pm    
¿Dispose? then wait for the Garbage Truck.
Nestor Arturo 27-Feb-12 16:35pm    
Sorry for the lack of seriousness, but we really need more details about what "dispose" means for your application.

When it comes to photographs in WPF, it's safe to assume that a photograph is a bitmap, and you would use one of the classes based on the class System.Windows.Media.Imaging.BitmapSource, http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapsource.aspx#inheritanceContinued[^].

These classes do not implement the interface System.IDisposable (http://msdn.microsoft.com/en-us/library/system.idisposable.aspx[^]) or any other means of explicit disposal, so you never need to dispose their instances.

You are working on a managed platform based on garbage collection. Most of the resources are reclaimed when an instance is being destructed automatically but a Garbage Collector (GC).

Please see:
http://msdn.microsoft.com/en-us/library/system.gc.aspx[^],
http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29[^].

In certain cases, explicit garbage collection is required, but in these cases the class implements System.IDisposable or some other disposal method (yes, there are few cases where some Dispose method is provided, the one unrelated to System.IDisposable).

—SA
 
Share this answer
 
If you need to delete files not matter other programs has those files opened (or locked) you have a big road ahead.
The Garbage Collector cleans in memory objects only (RAM). Disks or files are not in its field of action.
I think you cannot "unlock" files so you can delete them, as this surely breaks the locker program.
My advice: Do not try to "unlock" files. Just detect when you cannot perform deletion (using a simple try catch), and leave the locked files alone.
 
Share this answer
 
The issue you have hit here is that you have effectively taken a lock on the image. I briefly touch on this technique in my article Low impact images[^] here on Code Project. You can use a variation on this class to do what you want.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900