Click here to Skip to main content
15,881,027 members
Home / Discussions / C#
   

C#

 
SuggestionRe: Auto Connect For HeadSet Pin
Eddy Vluggen25-Mar-12 3:30
professionalEddy Vluggen25-Mar-12 3:30 
GeneralNokia Blocked my country Pin
Smart Arab25-Mar-12 6:30
Smart Arab25-Mar-12 6:30 
QuestionVisualt Studio 2008 Team Suite for Blackberry Pin
mauricemcse24-Mar-12 2:36
mauricemcse24-Mar-12 2:36 
AnswerRe: Visualt Studio 2008 Team Suite for Blackberry Pin
Wes Aday24-Mar-12 4:36
professionalWes Aday24-Mar-12 4:36 
QuestionThe process cannot access the file because it is being used by another process. Pin
ausia1924-Mar-12 2:34
ausia1924-Mar-12 2:34 
AnswerRe: The process cannot access the file because it is being used by another process. Pin
OriginalGriff24-Mar-12 2:51
mveOriginalGriff24-Mar-12 2:51 
AnswerRe: The process cannot access the file because it is being used by another process. Pin
Luc Pattyn24-Mar-12 3:55
sitebuilderLuc Pattyn24-Mar-12 3:55 
AnswerRe: The process cannot access the file because it is being used by another process. PinPopular
Alan N24-Mar-12 4:25
Alan N24-Mar-12 4:25 
The problem you have is caused by Image.FromFile http://support.microsoft.com/kb/309482[^] which is locking the file and preventing reuse in the same process. The reference to another process in the error message is very misleading.

The work arounds are
1) Create a new Bitmap from the Image and then dispose of the Image
2) Create the Image by using the FromStream method and then dispose of the FileStream

Example code for these are

C#
private const String ImageFile = @"E:\VC\Projects\CP\InUseImages\Pic.jpg";

private void LoadLockedImage() {
  using (Image temp = Image.FromFile(ImageFile)) {
    pictureBox1.Image = temp;

    // Cannot open the file again, will throw the 'file in use' exception
    using (FileStream fs = new FileStream(ImageFile, FileMode.Open)) {
    }
  }
}

private void LoadFreeImage() {
  using (Image temp = Image.FromFile(ImageFile)) {
    pictureBox1.Image = new Bitmap(temp);
  }

  // Can open the file again, 
  using (FileStream fs = new FileStream(ImageFile, FileMode.Open)) {
  }
}

private void LoadFreeImage2() {
  using (FileStream fs  = new FileStream(ImageFile, FileMode.Open)) {
    pictureBox1.Image = Image.FromStream(fs);
  }

  // Can open the file again
  using (FileStream fs = new FileStream(ImageFile, FileMode.Open)) {
  }
}


Alan.
GeneralRe: The process cannot access the file because it is being used by another process. Pin
ausia1924-Mar-12 5:38
ausia1924-Mar-12 5:38 
Questionc++ or c# or vb.net Pin
ssssdaaads23-Mar-12 23:52
ssssdaaads23-Mar-12 23:52 
AnswerRe: c++ or c# or vb.net Pin
Abhinav S24-Mar-12 0:08
Abhinav S24-Mar-12 0:08 
AnswerRe: c++ or c# or vb.net Pin
PIEBALDconsult24-Mar-12 3:42
mvePIEBALDconsult24-Mar-12 3:42 
AnswerRe: c++ or c# or vb.net Pin
Wes Aday24-Mar-12 4:33
professionalWes Aday24-Mar-12 4:33 
GeneralRe: c++ or c# or vb.net Pin
Vipin_Arora26-Mar-12 19:39
Vipin_Arora26-Mar-12 19:39 
AnswerRe: c++ or c# or vb.net Pin
ProEnggSoft25-Mar-12 2:33
ProEnggSoft25-Mar-12 2:33 
AnswerRe: c++ or c# or vb.net Pin
Vipin_Arora26-Mar-12 19:31
Vipin_Arora26-Mar-12 19:31 
Questionserver connect Pin
heba abu ghaleih22 23-Mar-12 13:40
heba abu ghaleih22 23-Mar-12 13:40 
AnswerRe: server connect Pin
Richard Andrew x6423-Mar-12 13:53
professionalRichard Andrew x6423-Mar-12 13:53 
GeneralRe: server connect Pin
heba abu ghaleih22 23-Mar-12 14:24
heba abu ghaleih22 23-Mar-12 14:24 
GeneralRe: server connect Pin
Richard Andrew x6423-Mar-12 14:25
professionalRichard Andrew x6423-Mar-12 14:25 
GeneralRe: server connect Pin
heba abu ghaleih22 23-Mar-12 14:27
heba abu ghaleih22 23-Mar-12 14:27 
GeneralRe: server connect Pin
Richard Andrew x6423-Mar-12 14:29
professionalRichard Andrew x6423-Mar-12 14:29 
GeneralRe: server connect Pin
heba abu ghaleih22 23-Mar-12 14:30
heba abu ghaleih22 23-Mar-12 14:30 
QuestionWinform graph Pin
DerecL23-Mar-12 11:14
DerecL23-Mar-12 11:14 
AnswerRe: Winform graph Pin
Eddy Vluggen23-Mar-12 11:24
professionalEddy Vluggen23-Mar-12 11:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.