Home > Net >  C # Winform procedure release resources not effective immediately
C # Winform procedure release resources not effective immediately

Time:09-17

Do c # winform development, meet the problem of deleting files, found that there will be no effect when the GC, described as follows:

Developed by the program will open the local image and display on the form, the user can through the delete button to delete the picture, prior to delete the related objects, for example, PictureBox release, and then use the File, delete () to delete files, found that cannot be deleted, cast UnauthorizedAccessException abnormalities,

Through before the PictureBox release and File before the Delete () to set breakpoints, found that there are different: before release, if removed manually File to quote the following prompt: operation cannot be completed, because the File is in XXX program open, after the release of the File. The Delete () before manually removing, prompt, the operation cannot be completed, because the File is in another program in the open, different places is pointed out the concrete application of the former, the latter did not say the program, the latter by shift + Delete this kind of circumstance can be deleted,

To sum up, not immediately effective c # Winform procedure to release resources, and not fully complete release,

CodePudding user response:

UnauthorizedAccessException abnormal, please make sure the file path is correct,

Did not the immediate execution of a GC recycling, but as long as the file object references to cancel, can delete files,

CodePudding user response:

You will find a lot of people is encapsulated into a method of

Bitmap Loadimage (string path)
{
Using (filestream)
{
Return Bitmap

}

}
Picturebox has a lot of weird takes up problems, abnormal problem, so, programmers have to develop "operation not only copy operation, original object" habit
  •  Tags:  
  • C#
  • Related