I am running into some interesting issues in my Main form. When I run my program, everything seems to run properly, but after the form loads, some of the functions I put in do not run and variables I have defined do not get new values. I'm not sure what could be causing the blocking of functionality. Below is what I have in the form load action. Below the EmailPort variable is what doesn't run.
I have looked at the question answered before at this link VS2010 does not show unhandled exception message in a WinForms Application on a 64-bit version of Windows and while it gives a good explanation of why this sort of thing happens, I am still unsure of how to make my errors clear so I can debug properly.
    Private Sub MainScreen_Load(sender As Object, e As EventArgs) Handles Me.Load
    'read project path
    Dim path As String = My.Application.Info.DirectoryPath
    'split base path to find root
    Dim BasePath() As String = Split(path, "bin")
    'Sets the current Directory
    Directory.SetCurrentDirectory(BasePath(0) & "Resources")
    'Creates a Path for the file
    Dim Serverpath As String = IO.Path.Combine(BasePath(0), "Resources\Server.ini")
    Dim Configpath As String = IO.Path.Combine(BasePath(0), "Resources\PLCconfig.ini")
    Dim EmailPath As String = IO.Path.Combine(BasePath(0), "Resources\emailIP.ini")
    'Creates a StreamReader
    Dim Server As New StreamReader(Serverpath)
    Dim Config As New StreamReader(Configpath)
    Dim EmailIP As New StreamReader(EmailPath)
    'Read the config file 
    Dim allLinesServer As List(Of String) = New List(Of String)
    Do While Not Server.EndOfStream
        allLinesServer.Add(Server.ReadLine())
    Loop
    Server.Close()
    Dim allLinesConfig As List(Of String) = New List(Of String)
    Do While Not Config.EndOfStream
        allLinesConfig.Add(Config.ReadLine())
    Loop
    Config.Close()
    Dim allLinesEmail As List(Of String) = New List(Of String)
    Do While Not EmailIP.EndOfStream
        allLinesEmail.Add(EmailIP.ReadLine())
    Loop
    EmailIP.Close()
    'server information
    ServerName = ReadLine(1, allLinesServer)
    ServerUser = ReadLine(2, allLinesServer)
    ServerPassword = ReadLine(3, allLinesServer)
    'PLC Config Info
    plcIP = ReadLine(1, allLinesConfig)
    plcTag1 = ReadLine(2, allLinesConfig)
    EthernetIPforCLXCom1.IPAddress = plcIP
    EthernetIPforCLXCom1.Write(plcTag1 & ".InputStat", 1)
    'Email Alert Information
    EmailHost = ReadLine(1, allLinesEmail)
    EmailPort = ReadLine(2, allLinesEmail) <--------- Here is where the form stops working
    'Data buffer for intial read in values
    For i As Integer = 0 To 499
        newDatareal(i) = 999.999
        outDatareal(i) = 999.999
        outputDataReals(i) = 999.999
    Next
    For i As Integer = 0 To 999
        newDatabits(i) = vbFalse
        outdatabits(i) = vbFalse
    Next
    'Set up the timer for IO Manager
    outputInitalize = True
    Timer3.Enabled = True
    Timer3.Interval = 1000
    'Checks to see if main screen is open by itself, if it is, open the main dialog screen
    For Each form In My.Application.OpenForms
        If (form.name = Name) Then
            'form is loaded so can do work 
            'if you need to check whether it is actually visible
            MainDialogScreen.Show()
            If form.Visible Then
                MainDialogScreen.TopMost = True
            End If
        End If
    Next
End Sub
I am using Visual Studio Community and AdvancedHMI v399a in my code.
Thanks in advance for any guidance you can provide
Edit: I found my error by moving the code I had to a button click like suggested. Because I was using a form load action, I was unable to find where the exception was happening. Lesson Learned. Thanks to Plutonix for the debug tip
 
    