1

In my Form1_Load event, the code execution stops for no reason the middle of nowhere, and just finishes the loading process at that instance, showing the gui, this is the code and the line where it stops:

Downloadn("https://somelinkhere.com/file.txt","Init.txt");
        Application.DoEvents();
        List<string> links = new List<string>();
        var lines = File.ReadAllLines("Init.txt"); //Code Stops and Gui Shows up after executing this code
        links.Add(lines[0].Split('^')[1]);
        links.Add(lines[1].Split('^')[1]);
        links.Add(lines[2].Split('^')[1]);
        links.Add(lines[3].Split('^')[1]);

The debugging process shows no errors, what could i be doing wrong ?

Zoe
  • 23,712
  • 16
  • 99
  • 132
Omarrrio
  • 924
  • 1
  • 12
  • 32
  • 1
    So you set a breakpoint on that line (or somewhere before), pushed `F11` once on that line and the program stops debugging with no errors? – Drew Kennedy Jun 06 '15 at 14:04
  • 1
    Why are you reading a file on load? You say GUI shows after executing the line, what did you think would happen? – artm Jun 06 '15 at 14:04
  • 1
    I wonder if an exception is being caught and swallowed somewhere, since by the sounds of it the program doesn't crash it merely skips some code. In VS, go to Debug\Exceptions, tick all the Thrown boxes and try again. If already ticked or that doesn't help, let us know. – Stephen Kennedy Jun 06 '15 at 14:05
  • What am i showing here, is only a part, it should keep step debugging, not stop debugging and show the gui, i expect it to go through the rest of the code. – Omarrrio Jun 06 '15 at 14:05
  • 1
    Is the code above in a `try-catch`? If not, place it inside one and see what happens. – Drew Kennedy Jun 06 '15 at 14:15
  • 1
    @StephenKennedy your comment helped me show up the exception, which was `System.IO.IOException`, aka the infamous Already being used error, any way to over come it ? – Omarrrio Jun 06 '15 at 14:17
  • 1
    In that case I've promoted my comment to an answer. Wrt to the second question, the obvious remedy is to ensure the file is not locked. However I think there might be a way to tell it to open up readonly. I'll check the docs. – Stephen Kennedy Jun 06 '15 at 14:21
  • 1
    Try this http://stackoverflow.com/a/27771453/397817 If no help, it probably needs to be a new question as I've resolved the issue of why code was being skipped. Hope that helps! Please let me know if it does or not! – Stephen Kennedy Jun 06 '15 at 14:23
  • 1
    I just added a dispose function to the WebClient at the end and it worked, thank you again. – Omarrrio Jun 06 '15 at 14:34

1 Answers1

2

I wonder if an exception is being caught and swallowed somewhere, since by the sounds of it the program doesn't crash it merely skips some code. In Visual Studio, go to Debug\Exceptions, tick all the Thrown boxes and try again. If my suspicion is correct, this will identify the problem.

Stephen Kennedy
  • 16,598
  • 21
  • 82
  • 98