Code Bug (Disposed Object?)
I am using the following codes:
This code triggers my transport sequence. I am not having any variable sequences.
Code:
Private Sub lblLab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblLab.Click
If boolTransportActive = False Then
lblTitle.Text = "CANNOT TRANSPORT"
lblTitle.ForeColor = Color.Red
Exit Sub
ElseIf boolTransportActive = True Then
If strCurrentLocation = "Lab" Then
strTransportTo = "Pet Store"
transport.Show()
Me.Close()
ElseIf strCurrentLocation = "Pet Store" Then
strTransportTo = "Lab"
transport.Show()
Me.Close()
End If
End If
This is the complete class for "transport".
Code:
Public Class transport
Private Sub transport_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Opacity = 0
Dim sngOpacity As Single
For sngOpacity = 0 To 1 Step 0.05
Me.Opacity = sngOpacity
Me.Refresh()
System.Threading.Thread.Sleep(50)
Next
currentframe.Close()
If strTransportTo = "Lab" Then
lab1a.Show()
lab1a.Opacity = 0
For sngOpacity = 0 To 1 Step 0.05
lab1a.Opacity = sngOpacity
lab1a.Refresh()
System.Threading.Thread.Sleep(50)
Next
ElseIf strTransportTo = "Pet Store" Then
hab1a.Show()
hab1a.Opacity = 0
For sngOpacity = 0 To 1 Step 0.05
hab1a.Opacity = sngOpacity
hab1a.Refresh()
System.Threading.Thread.Sleep(50)
Next
ElseIf strTransportTo = "News Station" Then
rnn1a.Show()
rnn1a.Opacity = 0
For sngOpacity = 0 To 1 Step 0.05
rnn1a.Opacity = sngOpacity
rnn1a.Refresh()
System.Threading.Thread.Sleep(50)
Next
End If
Me.Close()
End Sub
End Class
This is the error I am receiving:
Quote:
System.ObjectDisposedException was unhandled
Message=Cannot access a disposed object.
Object name: 'transport'.
ObjectName=transport
Source=System.Windows.Forms
StackTrace:
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Form.CreateHandle()
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.ContainerControl.FocusActiveControlInternal()
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.Show()
at WORD4WORD.transportgui.lblLab_Click(Object sender, EventArgs e) in \\Jasons-mac\seagate\MousePaw\Visual Basic Projects\WORD4WORD\WORD4WORD\transportgui.vb:line 15
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Label.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at WORD4WORD.WatchGUI.wbtnTransport_Click(Object sender, EventArgs e) in \\Jasons-mac\seagate\MousePaw\Visual Basic Projects\WORD4WORD\WORD4WORD\watchgui.vb:line 115
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at WORD4WORD.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
InnerException:
What is going wrong? I reach the error at the first instance of "transport.Show()"
Re: Code Bug (Disposed Object?)
why are you closing the form in the load event?
Re: Code Bug (Disposed Object?)
I'm making a game. The effect I am aiming for is to fade one screen to white, and then fade that to the new screen.