Fichier C#.Supprimer un fichier utilisé par un autre processus

J'ai un problème lorsque j'essaie de supprimer un fichier image.
J'ai toujours une erreur qui dit: IOExeption était non gérée. Acces refusé car le fichier est beining utilisé par un autre processus.

Je ne sais pas ce qui pourrait être et comment le résoudre.

private void comboBox3_SelectedIndexChanged(object sender, EventArgs e) 
{ 
Album album = GetAlbum(comboBox1.SelectedIndex); 
Photo Photo = GetPhoto(comboBox1.SelectedIndex, comboBox3.SelectedIndex); 

txtPhotoPath.Texte = Répertoire.GetCurrentDirectory() + "\\" + photo.SPath; 

lblExtention.Texte = photo.SExtention; 
txtPhotoTitle.Texte = photo.STitle; 
pctrbFoto.Image = Image.FromFile(foto.SPath).GetThumbnailImage(GetWitdth(photo.SPath, GetHeight(photo.SPath, 150)), GetfHeight(photo.SPath, 150), null, new IntPtr()); 
} 

private void btnChangePhoto_Click(object sender, EventArgs e) 
{ 
Album album = GetAlbum(comboBox1.SelectedIndex); 
Photo Photo = GetPhoto(comboBox1.SelectedIndex, comboBox3.SelectedIndex); 

Fichier.Supprimer("Albums\\Images\\" + photo.STitle + foto.SExtention); 

photo.SExtention = lblExtention.Texte; 
photo.STitle = txtPhotoTitel.Texte; 
Photo.SPath = txtPath.Texte; 

Fichier.Copie(photo.SPath, "Albums\\Images\\" + photo.STitle + photo.SExtention); 

}

Grâce,
Vinzcent


Merci à tous pour l'aide.

Je l'utilise et il fonctionne très bien maintenant


votre processus est celui qui utilise le fichier , vous devez régler l'image pour null utiliser quelque chose comme ceci :

var img = Image.FromFile(foto.SPath).GetThumbnailImage(GetWitdth(photo.SPath,
GetHeight(photo.SPath, 150)), GetfHeight(photo.SPath, 150), null, new IntPtr());

pctrbFoto.Image = img;

img = null;

GC.Collect();

InformationsquelleAutor Vinzcent | 2009-05-01