Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6589305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:09:24+00:00 2026-05-25T17:09:24+00:00

private void ButtonCustomarinfoEditClick(object sender, System.Windows.RoutedEventArgs e) { ByteToImage(fileName,bytesOfImage,fileSize); } private ImageSource ByteToImage(string fileName, byte[]

  • 0
private void ButtonCustomarinfoEditClick(object sender, System.Windows.RoutedEventArgs e)
    {
      ByteToImage(fileName,bytesOfImage,fileSize);
    }   

private ImageSource ByteToImage(string fileName, byte[] bytesOfImage, int fileSize)
    {
        FileStream imageFilestream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
        imageFilestream.Write(bytesOfImage, 0, fileSize);
        imageFilestream.Flush();
        imageFilestream.Close();
        imageFilestream.Dispose();
        BitmapImage myBitmapImage = new BitmapImage();
        myBitmapImage.BeginInit();
        myBitmapImage.UriSource = new Uri(fileName);
        myBitmapImage.DecodePixelWidth = 200;
        myBitmapImage.EndInit();
        return myBitmapImage;
    }

When i click ButtonCustomarinfoEdit fist time then it work`s fine. But When i click second time then it throw this exception

Caught: “The process cannot access the file ‘C:\20.jpg’ because it is being used by another process.” (System.IO.IOException)
Exception Message = “The process cannot access the file ‘C:\20.jpg’ because it is being used by another process.”, Exception Type = “System.IO.IOException”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:09:25+00:00Added an answer on May 25, 2026 at 5:09 pm

    Your BitmapImage object keeps the file locked.

    Just a small observation, please use the using statement like this:

    using(FileStream imageFilestream = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { 
            imageFilestream.Write(bytesOfImage, 0, fileSize); 
    }
    

    otherwise you might run into situations that your file will remain in use (if an exception will occur before you call the Close() method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

private void HeroMouseEnter(object sender, MouseEventArgs e) { ((Image)sender).Source = GetGlowingImage(((Image)sender).Name); } public ImageSource GetGlowingImage(string
private void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e) { App.Current.MainWindow.Visibility = System.Windows.Visibility.Visible; Close(); } A click/click
private void button1_Click(object sender, EventArgs e) { string name; name = textBox5.Text; SqlConnection con10
private void NuestroButton1_Click(object sender, RoutedEventArgs e) { if //the sender's .Text/.Content is X {
private void Form1_Load(object sender, EventArgs e) { GetDataTable(@C:\Documents and Settings\agordon\Desktop\ACTIVITYEX.csv); } public System.Data.DataTable GetDataTable(string
private void btn_friends_pressed(object sender, RoutedEventArgs e) { NavigationService.Navigate(new Uri(/Friends.xaml, UriKind.Relative)); } When I press
I know the GUI has private void Form1_Closing(object sender, System.ComponentModel.EventArgs e) { //do stuff
private void button6_Click(object sender, EventArgs e) { string[] filePaths = Directory.GetFiles(@c:\MyDir\); } And I
private void Form1_Load(object sender, EventArgs e) { GetDataTable(@C:\Documents and Settings\agordon\Desktop\ACTIVITYEX.log); } public System.Data.DataTable GetDataTable(string
private void btnTest_Click(object sender, RoutedEventArgs e) { try { worker.DoWork += delegate(object s, DoWorkEventArgs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.