"Cannot access disposed object" - Object is NOT disposed!

Module Startup
'create the instances of the form at this level so we can talk to it
Public gamescreen As New frmBehrendopoly
Public auct As New Auction
Dim mainscreen As New MainScreen

Public Sub Main()
Dim frmWelcomeNew As New welcome
Dim scrsize As New ScreenSize
Dim frmplay As New Players
Dim frmplyNames As New PlayerNames
frmWelcomeNew.ShowDialog() 'Displays Splash Screen
scrsize.ShowDialog()
frmplay.ShowDialog()
frmplyNames.ShowDialog()
mainscreen.ShowDialog()
'Displays main Form
End Sub

End Module

This code worked perfectly under VB.net 2003. After converting the project to VB 2005, I get the error "Cannot access disposed object". The error refers to the line:

scrsize.showdialog()

If I comment that out it works fine. scrsize is a form which contains a timer. The timer's tick event contains the code: Me.Close. The interval is set to 4500. I don't see why it happens.



Answer this question

"Cannot access disposed object" - Object is NOT disposed!

  • explode

    it may well be because of that however thats more than enough "time" for it to initialize and show the form without problems....what happens if you just disable the timer and run the app

    Do you need to have the timer there



  • Carl Daniel

    Apparently, that's NOT more than enough time! Your message gave me the idea to increase the timer interval and that fixed the problem! For what it's worth, through some experimentation, I discovered that with a timer interval of 4500, the problem occurs, but if I increase it to 5000, it doesn't. It's consistent and reproducible, 5000 or greater works, 4500 or less does not! Solves my problem, but doesn't answer the question, WHY

    Thank you for pointing me in the right direction


  • knvb

    its a story behind it probably. I'm not technically sure why apart from the application being slow in some way. Maybe if you enable the timer on the Form_Load event of that form which has the timer, instead of enabling it by default in designer view



  • "Cannot access disposed object" - Object is NOT disposed!