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

  • Home
  • SEARCH
  • 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 8589339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:01:53+00:00 2026-06-11T23:01:53+00:00

i keep getting this error file already use by another program whenever i try

  • 0

i keep getting this error “file already use by another program” whenever i try to write to an already opened file, although i used the “close()” and “flush()” commands, it still gives me the error, here is my code:

private void Openbtn_Click(object sender, EventArgs e)
    {
        textBox1.Text = "";
        listView1.Items.Clear();
        OpenFileDialog ofd = new OpenFileDialog();
        ofd.Title = "Open GSMB File";
        ofd.Filter = "GSMB Files (*.gsmb)|*.gsmb|All Files (*.*)|*.*";
        if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            MessageBox.Show("File opened Succesfully!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            path = ofd.FileName;
            BinaryReader br = new BinaryReader(File.OpenRead(path), Encoding.Unicode);
            BinaryReader brs = new BinaryReader(File.OpenRead(path), Encoding.Unicode);
            brs.BaseStream.Position = 0x4;
            menuItem9.Text = brs.ReadInt32().ToString();
            if (menuItem9.Text == "3620")
            {
                num_pointers = 204;
                menuItem8.Text = num_pointers.ToString();
            }
            else if (menuItem9.Text == "54662")
            {
                num_pointers = 2372;
                menuItem8.Text = num_pointers.ToString();
            }
            else if (menuItem9.Text == "9560")
            {
                num_pointers = 88;
                menuItem8.Text = num_pointers.ToString();
            }
            else if (menuItem9.Text == "1126")
            {
                num_pointers = 130;
                menuItem8.Text = num_pointers.ToString();
            }
            else if (menuItem9.Text == "342")
            {
                num_pointers = 16;
                menuItem8.Text = num_pointers.ToString();
            }
            else if (menuItem9.Text == "6232")
            {
                num_pointers = 467;
                menuItem8.Text = num_pointers.ToString();
            }
            else if (menuItem9.Text == "75698")
            {
                num_pointers = 498;
                menuItem8.Text = num_pointers.ToString();
            }
            else if (menuItem9.Text == "9914")
            {
                num_pointers = 110;
                menuItem8.Text = num_pointers.ToString();
            }
            else if (menuItem9.Text == "128")
            {
                num_pointers = 4;
                menuItem8.Text = num_pointers.ToString();
            }
            else if (menuItem9.Text == "5394")
            {
                num_pointers = 156;
                menuItem8.Text = num_pointers.ToString();
            }
            else if (menuItem9.Text == "12000")
            {
                num_pointers = 580;
                menuItem8.Text = num_pointers.ToString();
            }
            else 
            {
                MessageBox.Show("This is not a Pokémon Typing Adventure string file !", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            List<int> offsets = new List<int>();
            int startstr = 0x1C;
            br.BaseStream.Position = startstr;
            int startstrval = br.ReadInt32();
            for (int i = 4; i < (num_pointers * 4 + 1); i += 4)
            {
                br.BaseStream.Position = startstr + i;
                offsets.Add(br.ReadInt32() + startstrval);
            }
            Dictionary<int, string> values = new Dictionary<int, string>();
            for (int i = 0; i < offsets.Count; i++)
            {
                int currentOffset = offsets[i];

                int nextOffset = (i + 1) < offsets.Count ? offsets[i + 1] : (int)br.BaseStream.Length;

                int stringLength = (nextOffset - currentOffset - 1) / 2;

                br.BaseStream.Position = currentOffset;

                var chars = br.ReadChars(stringLength);
                values.Add(currentOffset, new String(chars));
            }
            foreach (int offset in offsets)
            {
                listView1.Items.Add(offset.ToString("X")).SubItems.Add(values[offset]);
             listView1.Items[offset].SubItems[1].Text.Replace(System.Environment.NewLine, "\n");
            }

            br.Close();
            br = null;
        }
        ofd.Dispose();
        ofd = null;
    }
private void menuItem10_Click(object sender, EventArgs e)
    {
        BinaryWriter bw = new BinaryWriter(File.OpenWrite(path));

        bw.BaseStream.Position = 0x20;
        int number_pointers = Convert.ToInt32(num_pointers);
        Encoding enc = Encoding.Unicode;

        bw.Write(number_pointers);

        int curr_pointer = 4 + number_pointers * 4;
        for (int i = 0; i < number_pointers; i++)
        {
            bw.Write(curr_pointer);
            curr_pointer += enc.GetByteCount(listView1.Items[i].SubItems[1].Text) + 2;
        }

        for (int i = 0; i < number_pointers; i++)
            bw.Write(enc.GetBytes(listView1.Items[i].SubItems[1].Text + '\0'));

        bw.Flush();
        bw.Close();
        bw = null;
    }

thank you, and i apologize for any disturbance.
PS: please do not post usless comments and answers such as “seach in google”, “we already answered these types of questions”, etc…
i spent 5 hours looking in google for an answer and nothing came up but using the ofd.close(), and i searched also in the stackoverflow website for similiar question, same answer, thank you.

  • 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-06-11T23:01:55+00:00Added an answer on June 11, 2026 at 11:01 pm

    Since you have no exception handling inside this function, if an exception occurs, it won’t continue, therefore never execute the br.Close(); function.

    You should use try { } finally { } to ensure it’s closed.

    private void Openbtn_Click(object sender, EventArgs e)
    {
        textBox1.Text = "";
        listView1.Items.Clear();
        OpenFileDialog ofd = new OpenFileDialog();
        ofd.Title = "Open GSMB File";
        ofd.Filter = "GSMB Files (*.gsmb)|*.gsmb|All Files (*.*)|*.*";
        if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            try {
                MessageBox.Show("File opened Succesfully!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                path = ofd.FileName;
                BinaryReader br = new BinaryReader(File.OpenRead(path), Encoding.Unicode);
                BinaryReader brs = new BinaryReader(File.OpenRead(path), Encoding.Unicode);
                brs.BaseStream.Position = 0x4;
                menuItem9.Text = brs.ReadInt32().ToString();
                if (menuItem9.Text == "3620")
                {
                    num_pointers = 204;
                    menuItem8.Text = num_pointers.ToString();
                }
                else if (menuItem9.Text == "54662")
                {
                    num_pointers = 2372;
                    menuItem8.Text = num_pointers.ToString();
                }
                else if (menuItem9.Text == "9560")
                {
                    num_pointers = 88;
                    menuItem8.Text = num_pointers.ToString();
                }
                else if (menuItem9.Text == "1126")
                {
                    num_pointers = 130;
                    menuItem8.Text = num_pointers.ToString();
                }
                else if (menuItem9.Text == "342")
                {
                    num_pointers = 16;
                    menuItem8.Text = num_pointers.ToString();
                }
                else if (menuItem9.Text == "6232")
                {
                    num_pointers = 467;
                    menuItem8.Text = num_pointers.ToString();
                }
                else if (menuItem9.Text == "75698")
                {
                    num_pointers = 498;
                    menuItem8.Text = num_pointers.ToString();
                }
                else if (menuItem9.Text == "9914")
                {
                    num_pointers = 110;
                    menuItem8.Text = num_pointers.ToString();
                }
                else if (menuItem9.Text == "128")
                {
                    num_pointers = 4;
                    menuItem8.Text = num_pointers.ToString();
                }
                else if (menuItem9.Text == "5394")
                {
                    num_pointers = 156;
                    menuItem8.Text = num_pointers.ToString();
                }
                else if (menuItem9.Text == "12000")
                {
                    num_pointers = 580;
                    menuItem8.Text = num_pointers.ToString();
                }
                else 
                {
                    MessageBox.Show("This is not a Pokémon Typing Adventure string file !", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                List<int> offsets = new List<int>();
                int startstr = 0x1C;
                br.BaseStream.Position = startstr;
                int startstrval = br.ReadInt32();
                for (int i = 4; i < (num_pointers * 4 + 1); i += 4)
                {
                    br.BaseStream.Position = startstr + i;
                    offsets.Add(br.ReadInt32() + startstrval);
                }
                Dictionary<int, string> values = new Dictionary<int, string>();
                for (int i = 0; i < offsets.Count; i++)
                {
                    int currentOffset = offsets[i];
    
                    int nextOffset = (i + 1) < offsets.Count ? offsets[i + 1] : (int)br.BaseStream.Length;
    
                    int stringLength = (nextOffset - currentOffset - 1) / 2;
    
                    br.BaseStream.Position = currentOffset;
    
                    var chars = br.ReadChars(stringLength);
                    values.Add(currentOffset, new String(chars));
                }
                foreach (int offset in offsets)
                {
                    listView1.Items.Add(offset.ToString("X")).SubItems.Add(values[offset]);
                 listView1.Items[offset].SubItems[1].Text.Replace(System.Environment.NewLine, "\n");
                }               
            }
            finally {
                br.Close();
                br = null;
            }
        }
        ofd.Dispose();
        ofd = null;
    }
    private void menuItem10_Click(object sender, EventArgs e)
        {
        BinaryWriter bw;
        try {
            bw = new BinaryWriter(File.OpenWrite(path));
    
            bw.BaseStream.Position = 0x20;
            int number_pointers = Convert.ToInt32(num_pointers);
            Encoding enc = Encoding.Unicode;
    
            bw.Write(number_pointers);
    
            int curr_pointer = 4 + number_pointers * 4;
            for (int i = 0; i < number_pointers; i++)
            {
                bw.Write(curr_pointer);
                curr_pointer += enc.GetByteCount(listView1.Items[i].SubItems[1].Text) + 2;
            }
    
            for (int i = 0; i < number_pointers; i++)
                bw.Write(enc.GetBytes(listView1.Items[i].SubItems[1].Text + '\0'));
        }
        finally {
            bw.Flush();
            bw.Close();
            bw = null;
        }
    }
    

    I’m also not sure if you should show a msgbox that shows “file opened succesfully ” right at the beginning of your logic.

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

Sidebar

Related Questions

I keep getting this error, although the file still gets moved into the correct
When I try to browse my service.svc file,I keep getting this error. I've enabled
I keep getting this error when I try to commit a group of executed
I keep getting this error: Could not load file or assembly 'Facebook, Version=5.4.1.0, Culture=neutral,
I keep getting a strange error inside my App.xaml file: Element is already the
I keep getting this error whenever I run unit tests in IntelliJ IDEA: /home/egervari/IdeaProjects/jobprep-stable/src/main/resources/dict/noun.txt
I'm trying to use slime from CVS (2009-01-05) but keep getting this error: LOAD:
I keep getting this error while reading a text file. Is it possible to
I am trying to write naive bayes classifier and I keep getting this error:
When I try to run rake db:migrate I keep getting this error: rake aborted!

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.