4 Replies - 193 Views - Last Post: 12 February 2019 - 07:03 PM Rate Topic: -----

#1 Omarado   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 91
  • Joined: 22-September 15

cannot access a disposed object

Posted 12 February 2019 - 04:07 PM

When I try to run my application , I get this error:

cannot access a disposed object

It happens when I try to open up a form and it should be the first code that gets ever applied in the application.

code for Form1_Load event:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        loginform.Show()
        loginform.WindowState = FormWindowState.Normal
        CheckForIllegalCrossThreadCalls = False
        Me.WindowState = FormWindowState.Minimized
        lastupdate.Text = My.Settings.lastupdate
        PPupdated.Text = My.Settings.PPrefreshed
        currenttime.Text = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
        If IsConnectionAvailable() = True Then
            connectortxt.Text = "Connected"
            If My.Settings.logged = True Then
                If My.Settings.autorefresh = True Then
                    HomeTabRefresh()
                    Timer1.Interval = 100 'how often to update display
                    Timer1.Start() 'start the display updater
                    stpw.Reset() 'restart the stopwatch
                    stpw.Start()
                Else
                    OfflineLoading()
                End If
            Else
                refresher.Visible = False
                reloglbl.Visible = True
                OfflineLoading()
            End If
            connectortxt.ForeColor = Color.Green
            publicip.Text = GetExternalIp()
        Else
            connectortxt.Text = "No Internet"
            connectortxt.ForeColor = Color.Red
            retrier.Visible = True
            publicip.Text = "No Internet"
        End If
    End Sub


the exception happens on the first line when I try to show the loginform.vb . The program has a splash screen which is set to be Form2. Form2 has no events at all, it is all about a picturebox. The program used to run fine until this error suddenly appeared out of nowhere. last thing I can remember I did before getting this error was pressing the "synchronize" button in the application settings.

Is This A Good Question/Topic? 0
  • +

Replies To: cannot access a disposed object

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14854
  • View blog
  • Posts: 59,272
  • Joined: 12-June 08

Re: cannot access a disposed object

Posted 12 February 2019 - 04:10 PM

is 'loginform' the name of the form in the project, or the name of a variable that is an instance of some form?
Was This Post Helpful? 0
  • +
  • -

#3 Omarado   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 91
  • Joined: 22-September 15

Re: cannot access a disposed object

Posted 12 February 2019 - 04:12 PM

View Postmodi123_1, on 13 February 2019 - 01:10 AM, said:

is 'loginform' the name of the form in the project, or the name of a variable that is an instance of some form?


It is the name of the form inside the project. It was created with that name. Nothing else has the same name.
Was This Post Helpful? 0
  • +
  • -

#4 Omarado   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 91
  • Joined: 22-September 15

Re: cannot access a disposed object

Posted 12 February 2019 - 04:34 PM

so I just fixed this error but I still don't get why it happens in the first place.
The loginform has its TopMost property set to true. When the loginform.show is called in Form1 it gives me that exception.

When I set the TopMost property to false then it worked normally. I bypassed this by setting a timer on the loginform which is enabled by default and ticks 1 second later and sets the form TopMost to true.

loginform Load event:

Private Sub loginform_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ComboBox1.SelectedIndex = 0
        If IsConnectionAvailable() = True Then
            connectortxt.Text = "Connected"
            connectortxt.ForeColor = Color.Green
            OK.Enabled = True
            signupbtn.Enabled = True
            offliner.Visible = False
            If My.Settings.autologin = True Then
                Dim thecode As String = My.Settings.Passcode
                If thecode <> Nothing Then
                    If Form1.IsConnectionAvailable = True Then
                        Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("I HID THE URL MYSELF AND NO ERROR HAPPENS HERE")
                        Dim response As System.Net.HttpWebResponse = request.GetResponse()
                        Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
                        Dim therealcode As String = sr.ReadToEnd()
                        If therealcode.Contains(thecode) Then
                            Form1.Download_Dropbox("I HID THE URL MYSELF AND NO ERROR HAPPENS HERE", CurDir & "\LOGINCODE.txt")
                            Dim fileContents As String
                            fileContents = My.Computer.FileSystem.ReadAllText(CurDir & "\LOGINCODE.txt")
                            If fileContents = thecode Then
                                My.Computer.FileSystem.DeleteFile(CurDir & "\LOGINCODE.txt", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
                                Form1.Enabled = True
                                Form1.WindowState = FormWindowState.Normal
                                My.Settings.OfflineLogger = True
                                My.Settings.logged = True
                                offliner.Visible = False
                                My.Settings.Passcode = thecode
                                Me.Close()
                                Form1.Enabled = True
                                Form1.WindowState = FormWindowState.Normal
                                My.Settings.OfflineLogger = True
                                My.Settings.logged = True
                                My.Settings.firsttime = False
                                If My.Settings.autorefresh = True Then
                                    Form1.refresher.Visible = True
                                    Form1.reloglbl.Visible = False
                                    Form1.HomeTabRefresh()
                                    Form1.Timer1.Interval = 100 'how often to update display
                                    Form1.Timer1.Start() 'start the display updater
                                    Form1.TimerRestart()
                                Else
                                    Form1.OfflineLoading()
                                End If
                            Else
                                My.Computer.FileSystem.DeleteFile(CurDir & "\LOGINCODE.txt", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
                                MsgBox("Incorrect Passcode")
                                My.Settings.Passcode = Nothing
                                offliner.Visible = True
                            End If
                        Else
                            MsgBox("Incorrect Passcode")
                            My.Settings.Passcode = Nothing
                            offliner.Visible = True
                        End If
                    Else
                        MsgBox("You must be connected to the internet to login.")
                    End If
                Else
                End If
            End If
        Else
            connectortxt.Text = "No Internet"
            connectortxt.ForeColor = Color.Red
            OK.Enabled = False
            signupbtn.Enabled = False
            retrier.Visible = True
            offliner.Visible = True

        End If
        Me.WindowState = FormWindowState.Normal
    End Sub



This exception only happened when I had the "My.settings.autologin" setting set to true which applies saved credentials automactily on form load. so this exception only happens with the TopMost property when "My.settings.autologin" is set to true. any idea why judging from the code above?

This post has been edited by Omarado: 12 February 2019 - 04:35 PM

Was This Post Helpful? 0
  • +
  • -

#5 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14854
  • View blog
  • Posts: 59,272
  • Joined: 12-June 08

Re: cannot access a disposed object

Posted 12 February 2019 - 07:03 PM

Quote

It is the name of the form inside the project. It was created with that name.

Then that's part of the issue. You create an instance of the form and then show that object. It allows an actual object instance to go through, load, initialize, etc and exist.


If my form was named 'form1' then I would do something like:

dim foo = new form1
foo.show

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1