|
-
May 13th, 2005, 02:02 PM
#1
Thread Starter
Addicted Member
Problem with Disposed objects [Resolved]
Hey everyone,
I created a program that searches Active Directory. I built the release version and it runs as it should. The problem comes up if I attempt to reopen the search form from the system tray again I get this error.
"Cannot access a disposed object named "Search"
I think the problem is coming up when the garbage collection runs it deletes the Search Form object out of memory. How can I prevent this from happening in my program?
"just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.ObjectDisposedException: Cannot access a disposed object named "Search".
Object name: "Search".
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Form.CreateHandle()
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at Active_Directory_Advanced_Search.sysTray.ShowFormSelect(Object sender, EventArgs e)
at Active_Directory_Advanced_Search.sysTray.NotifyIcon_DoubleClick(Object sender, EventArgs e)
at System.Windows.Forms.NotifyIcon.OnDoubleClick(EventArgs e)
at System.Windows.Forms.NotifyIcon.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.NotifyIcon.WndProc(Message& msg)
at System.Windows.Forms.NotifyIconNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)"
Last edited by Porsche944; May 13th, 2005 at 03:17 PM.
-
May 13th, 2005, 02:07 PM
#2
Re: Problem with Disposed objects
Either create a new instance each time you want to show it (since you are disposing it upon close of that form, probably) or create
a public var set to the search form and create it on first use. Then just do a .Show/.Hide instead of disposing of it.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 13th, 2005, 02:26 PM
#3
Thread Starter
Addicted Member
Re: Problem with Disposed objects
How should I change my code to just show and hide the form ?
Here is my code as it is now.
In System Tray Form
Code:
Private Sub ShowFormSelect(ByVal sender As Object, ByVal e As System.EventArgs)
'Display SettingsForm dialog if it is not already displayed.
If mSettingsForm Is Nothing Then
mSettingsForm = New Search
mSettingsForm.ShowDialog()
Else
If mSettingsForm.Visible = False Then
mSettingsForm.Visible = True
End If
mSettingsForm.Activate()
End If
End Sub
In system tray form Declarations
Code:
Private mSettingsForm As Search
Under what event in the search form should I put
me.hide ?
-
May 13th, 2005, 02:32 PM
#4
Re: Problem with Disposed objects
In the close button's click event, but its being shown modally so that will hold up the process.
Will it messup any of your other code to just do a .Show instead of a .ShowDialog?
You could hide the calling form from the form that is calling the search and show it again upon the close buttons click
event in the search form.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 13th, 2005, 02:56 PM
#5
Thread Starter
Addicted Member
Re: Problem with Disposed objects
No I went ahead and changed it from showdialog to show. I can't find the event for the on click close command. All I see in the event viewer is closed and closing i tried me.hide in each but i still get this error.
-
May 13th, 2005, 03:02 PM
#6
Re: Problem with Disposed objects
You should do something like...
VB Code:
'Behind search form
Private Sub frmSearch_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Me.Hide()
otherform.Show
End Sub
'Behind main form
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
ShowFormSelect(sender, e)
Me.Hide
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|