3

A part of my form Load Event is neither accessed (breakpoint is not executed) nor executed (message box not showing), this is my code

private void Form1_Load(object sender, EventArgs e)
    {
        OpenFileDialog ofd = new OpenFileDialog();
        ofd.Title = "Open .ODI file";
        ofd.Filter = "ODI Files (*.odi)|*odi";
        DialogResult result = ofd.ShowDialog();
        if (result == DialogResult.Cancel)
            return;
        MessageBox.Show("bla");
        FileStream fs = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read);
        FileStream fs1 = new FileStream(Path.GetDirectoryName(ofd.FileName) + "\\VOL1.DAT", FileMode.Open, FileAccess.Read);
        //------------------------CODE IS NOT EXECUTED AFTER THIS
        MessageBox.Show("bla2");
        //getting the Main Folders
        byte[] fldrn = new byte[4]; 
        fs.Position = 0x74;
        fs.Read(fldrn, 0, 4);
        int fldrnum = BitConverter.ToInt32(fldrn, 0);
        MessageBox.Show(fldrnum.ToString(), "1");

        byte[] namaes = new byte[28];
        foldernames = new string[fldrnum];
        for (int i = 0; i < fldrnum; i++)
        {
            fs.Position = 0x88 + i*4;
            fs.Position = 0x74;
            fs.Read(fldrn, 0, 4);
            int fldrnam = BitConverter.ToInt32(fldrn, 0);
            int pos = (int)fs.Position;

            fs.Position = pos + fldrnam;
            fs.Read(namaes, 0, 28);
            foldernames[i] = Encoding.ASCII.GetString(namaes).Split('\0')[0];
            MessageBox.Show(foldernames[i], i.ToString());
            treeView1.Nodes[0].Nodes[0].Nodes.Add(foldernames[i]).ImageIndex = 1;
        }
    }
Omarrrio
  • 1,075
  • 1
  • 16
  • 34

3 Answers3

1

Do you have something like this in your constructor? Would be best to have this in the designer file if it is windows forms.

this.Load += new EventHandler( Form1_Load);

DROP TABLE users
  • 1,955
  • 14
  • 26
  • 1
    i think thix is a window form app.. so that code must b generated in designer class.. – rummykhan Mar 07 '14 at 22:10
  • @rummykhan that would be the best place for it to be but it wold work in a constructor. I was just trying to identify if attaching the event was the problem. – DROP TABLE users Mar 07 '14 at 22:10
  • 2
    @Omarrrio: For future reference, pictures of code are next to useless for most purposes. Most people would very much prefer if you post code on a site like http://pastebin.com or http://ideone.com (or, even better, if you simply add it to the question so future visitors don't have to ask about it again). – cHao Mar 07 '14 at 22:47
  • 1
    @cHao, thank you and sorry, i won't let it happen again. – Omarrrio Mar 07 '14 at 22:54
1
private void Form1_Load(object sender, EventArgs e)
    {
        OpenFileDialog ofd = new OpenFileDialog();
        ofd.Title = "Open .ODI file";
        ofd.Filter = "ODI Files (*.odi)|*odi";
        DialogResult result = ofd.ShowDialog();
        if (result == DialogResult.Cancel)
            //return;   jux remove this return and ur code will work fine
            // actually we dont use return in the body of if condition.. bad practice

        MessageBox.Show("bla");
        FileStream fs = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read);
        FileStream fs1 = new FileStream(Path.GetDirectoryName(ofd.FileName) + "\\VOL1.DAT", FileMode.Open, FileAccess.Read);
        //------------------------CODE IS NOT EXECUTED AFTER THIS
        MessageBox.Show("bla2");
        //getting the Main Folders
        byte[] fldrn = new byte[4]; 
        fs.Position = 0x74;
        fs.Read(fldrn, 0, 4);
        int fldrnum = BitConverter.ToInt32(fldrn, 0);
        MessageBox.Show(fldrnum.ToString(), "1");

        byte[] namaes = new byte[28];
        foldernames = new string[fldrnum];
        for (int i = 0; i < fldrnum; i++)
        {
            fs.Position = 0x88 + i*4;
            fs.Position = 0x74;
            fs.Read(fldrn, 0, 4);
            int fldrnam = BitConverter.ToInt32(fldrn, 0);
            int pos = (int)fs.Position;

            fs.Position = pos + fldrnam;
            fs.Read(namaes, 0, 28);
            foldernames[i] = Encoding.ASCII.GetString(namaes).Split('\0')[0];
            MessageBox.Show(foldernames[i], i.ToString());
            treeView1.Nodes[0].Nodes[0].Nodes.Add(foldernames[i]).ImageIndex = 1;
        }
    }
rummykhan
  • 2,603
  • 3
  • 18
  • 35
  • it still doesn't work, but when i remove the fs1 filestream, it works – Omarrrio Mar 07 '14 at 22:19
  • 2
    _actually we dont use return in the body of if condition.. bad practice_ That is ridiculous. – Silvermind Mar 07 '14 at 22:20
  • 1
    well it's not bad practice, it makes sure the code is NOT executed if the cancel button is pressed – Omarrrio Mar 07 '14 at 22:23
  • 3
    Of course you understand that I mean that it is ridiculous to say that it is bad practice. It is just an eager return. Put it between braces and it is clear as day what is happening. – Silvermind Mar 07 '14 at 22:24
1

I found the answer, i was accessing a file already in use by one of my windows processes(fs1), it didn't throw an exception though, this is by far explained in this answer: VS2010 does not show unhandled exception message in a WinForms Application on a 64-bit version of Windows

Community
  • 1
  • 1
Omarrrio
  • 1,075
  • 1
  • 16
  • 34