Click here to Skip to main content
15,558,352 members
Home / Discussions / C#
   

C#

 
SuggestionRe: Auto Connect For HeadSet Pin
Eddy Vluggen25-Mar-12 4:30
professionalEddy Vluggen25-Mar-12 4:30 
GeneralNokia Blocked my country Pin
Smart Arab25-Mar-12 7:30
Smart Arab25-Mar-12 7:30 
QuestionVisualt Studio 2008 Team Suite for Blackberry Pin
mauricemcse24-Mar-12 3:36
mauricemcse24-Mar-12 3:36 
AnswerRe: Visualt Studio 2008 Team Suite for Blackberry Pin
Wes Aday24-Mar-12 5:36
professionalWes Aday24-Mar-12 5:36 
QuestionThe process cannot access the file because it is being used by another process. Pin
ausia1924-Mar-12 3:34
ausia1924-Mar-12 3:34 
AnswerRe: The process cannot access the file because it is being used by another process. Pin
OriginalGriff24-Mar-12 3:51
mveOriginalGriff24-Mar-12 3:51 
AnswerRe: The process cannot access the file because it is being used by another process. Pin
Luc Pattyn24-Mar-12 4:55
sitebuilderLuc Pattyn24-Mar-12 4:55 
AnswerRe: The process cannot access the file because it is being used by another process. PinPopular
Alan N24-Mar-12 5:25
Alan N24-Mar-12 5: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 6:38
ausia1924-Mar-12 6:38 
Questionc++ or c# or vb.net Pin
ssssdaaads24-Mar-12 0:52
ssssdaaads24-Mar-12 0:52 
AnswerRe: c++ or c# or vb.net Pin
Abhinav S24-Mar-12 1:08
Abhinav S24-Mar-12 1:08 
AnswerRe: c++ or c# or vb.net Pin
PIEBALDconsult24-Mar-12 4:42
professionalPIEBALDconsult24-Mar-12 4:42 
AnswerRe: c++ or c# or vb.net Pin
Wes Aday24-Mar-12 5:33
professionalWes Aday24-Mar-12 5:33 
GeneralRe: c++ or c# or vb.net Pin
Vipin_Arora26-Mar-12 20:39
Vipin_Arora26-Mar-12 20:39 
AnswerRe: c++ or c# or vb.net Pin
ProEnggSoft25-Mar-12 3:33
ProEnggSoft25-Mar-12 3:33 
AnswerRe: c++ or c# or vb.net Pin
Vipin_Arora26-Mar-12 20:31
Vipin_Arora26-Mar-12 20:31 
Questionserver connect Pin
heba abu ghaleih22 23-Mar-12 14:40
heba abu ghaleih22 23-Mar-12 14:40 
AnswerRe: server connect Pin
Richard Andrew x6423-Mar-12 14:53
professionalRichard Andrew x6423-Mar-12 14:53 
GeneralRe: server connect Pin
heba abu ghaleih22 23-Mar-12 15:24
heba abu ghaleih22 23-Mar-12 15:24 
GeneralRe: server connect Pin
Richard Andrew x6423-Mar-12 15:25
professionalRichard Andrew x6423-Mar-12 15:25 
GeneralRe: server connect Pin
heba abu ghaleih22 23-Mar-12 15:27
heba abu ghaleih22 23-Mar-12 15:27 
GeneralRe: server connect Pin
Richard Andrew x6423-Mar-12 15:29
professionalRichard Andrew x6423-Mar-12 15:29 
GeneralRe: server connect Pin
heba abu ghaleih22 23-Mar-12 15:30
heba abu ghaleih22 23-Mar-12 15:30 
QuestionWinform graph Pin
DerecL23-Mar-12 12:14
DerecL23-Mar-12 12:14 
AnswerRe: Winform graph Pin
Eddy Vluggen23-Mar-12 12:24
professionalEddy Vluggen23-Mar-12 12: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.