473,698 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

formArray close / dispose issue

I have created myself an issue, and perhaps my idea wasn't as bright as I
thought it was originally.
If someone can help me figure out what the correct train of thought should
be - or if there is a solution to this one.

I created a dummy mdi app.
In the main form ( frmMainScreen ) I created a variable as such:
<written in notepad to trim everything down>

Public Shared frmFormsOpen() As frmMyTestForm

Now, in a totally seperate sub form opend from the main form I do this on a
button click:

LengthOfGames = (frmMainScreen. frmFormsOpen.Le ngth - 1)
ReDim Preserve frmMainScreen.f rmFormsOpen(Len gthOfGames)

frmMainScreen.f rmFormsOpen(Len gthOfGames) = New frmMyTestForm
frmMainScreen.f rmFormsOpen(Len gthOfGames).Mdi Parent = Me.MdiParent
'Remember that this form is also an mdi child of the main form.
'Set my own property for later use
frmMainScreen.f rmFormsOpen(Len gthOfGames).Gam eID = anIntegerValue

frmMainScreen.f rmFormsOpen(Len gthOfGames).Sho w()

'Works Great
So in other code on other child forms forms I can do stuff like this:

For Each SearchForm As frmMyTestForm In
frmMainScreen.f rmFormsOpen
If SearchForm.Game ID = mytestID Then 'mytestID is set to a
value from something else
SearchForm.Brin gToFront()
Exit For
End If
Next
My problem is this:

where do i actually remove the array element when the form is closed. I do
not want it to stay in the array.
I do not think I can do it in the _FormClosed of the
frmMainScreen.f rmFormsOpen(Len gthOfGames)._Fo rmClosed
because I am actually in the form itself still - so I am assuming I cannot
kill the object when I am still using the object.
( im trying to kill myself from myself ).

That is my issue I have created myself and I was wondering if someone can
point me in the right direction on how to get around this issue.

Thanks,

Miro

Oct 29 '08 #1
10 1243
"Miro" <mi**@beero.com schrieb
where do i actually remove the array element when the form is
closed. I do not want it to stay in the array.
Do yourself a favor and use a List(Of frmMyTestForm) instead of the array.
(which VB version?) Safes you from item shifting and redimming.
I do not think I can do it in the _FormClosed of the
frmMainScreen.f rmFormsOpen(Len gthOfGames)._Fo rmClosed
because I am actually in the form itself still - so I am assuming I
cannot kill the object when I am still using the object.
( im trying to kill myself from myself ).
You don't kill anything by removing one reference. You can safely remove the
item from the list in the FormClosed event. The object on which the current
method is executed is never destroyed.
Armin

Oct 29 '08 #2
Its vb 2008

Thank you for the post.
I was under the impression - since I am 'sitting' in the object still during
_FormClose then I cannot Remove my object from underneith my feet.

Im assuming then by your statement
>The object on which the current method is executed is never destroyed.
That once I leave the form and it does close - it will be destroyed in the
background - I dont need to run anything else?

I will google and search up "List" to use a list instead of an array.

Thank you,

Miro

"Armin Zingler" <az*******@free net.dewrote in message
news:ub******** ******@TK2MSFTN GP02.phx.gbl...
"Miro" <mi**@beero.com schrieb
>where do i actually remove the array element when the form is
closed. I do not want it to stay in the array.

Do yourself a favor and use a List(Of frmMyTestForm) instead of the array.
(which VB version?) Safes you from item shifting and redimming.
>I do not think I can do it in the _FormClosed of the
frmMainScreen. frmFormsOpen(Le ngthOfGames)._F ormClosed
because I am actually in the form itself still - so I am assuming I
cannot kill the object when I am still using the object.
( im trying to kill myself from myself ).

You don't kill anything by removing one reference. You can safely remove
the
item from the list in the FormClosed event. The object on which the
current method is executed is never destroyed.
Armin
Oct 29 '08 #3
"Miro" <mi**@beero.com schrieb
Im assuming then by your statement
>>The object on which the current method is executed is never destroyed.
That once I leave the form and it does close - it will be destroyed in the
background - I dont need to run anything else?
Yes, nothing else is required.
I will google and search up "List" to use a list instead of an array.
Not required to google - look in the object browser. It's
System.Collecti ons.Generic.Lis t(Of T)

see also:
http://msdn.microsoft.com/en-us/library/41107z8a.aspx
Armin

Oct 29 '08 #4
Miro,

You can find all the mdi forms by using
\\\
me.MDIParent.MD IChildren
///

http://msdn.microsoft.com/en-us/libr...ichildren.aspx

Probably much easier,

Cor
"Miro" <mi**@beero.com schreef in bericht
news:Os******** ********@TK2MSF TNGP03.phx.gbl. ..
>I have created myself an issue, and perhaps my idea wasn't as bright as I
thought it was originally.
If someone can help me figure out what the correct train of thought should
be - or if there is a solution to this one.

I created a dummy mdi app.
In the main form ( frmMainScreen ) I created a variable as such:
<written in notepad to trim everything down>

Public Shared frmFormsOpen() As frmMyTestForm

Now, in a totally seperate sub form opend from the main form I do this on
a button click:

LengthOfGames = (frmMainScreen. frmFormsOpen.Le ngth - 1)
ReDim Preserve frmMainScreen.f rmFormsOpen(Len gthOfGames)

frmMainScreen.f rmFormsOpen(Len gthOfGames) = New frmMyTestForm
frmMainScreen.f rmFormsOpen(Len gthOfGames).Mdi Parent = Me.MdiParent
'Remember that this form is also an mdi child of the main form.
'Set my own property for later use
frmMainScreen.f rmFormsOpen(Len gthOfGames).Gam eID = anIntegerValue

frmMainScreen.f rmFormsOpen(Len gthOfGames).Sho w()

'Works Great
So in other code on other child forms forms I can do stuff like this:

For Each SearchForm As frmMyTestForm In
frmMainScreen.f rmFormsOpen
If SearchForm.Game ID = mytestID Then 'mytestID is set to a
value from something else
SearchForm.Brin gToFront()
Exit For
End If
Next
My problem is this:

where do i actually remove the array element when the form is closed. I
do not want it to stay in the array.
I do not think I can do it in the _FormClosed of the
frmMainScreen.f rmFormsOpen(Len gthOfGames)._Fo rmClosed
because I am actually in the form itself still - so I am assuming I cannot
kill the object when I am still using the object.
( im trying to kill myself from myself ).

That is my issue I have created myself and I was wondering if someone can
point me in the right direction on how to get around this issue.

Thanks,

Miro

Oct 29 '08 #5
You are confusing removing a reference to an object from a list with
destruction of the object.

An object can have many references. Removing those references does
nothing other than, when all references have been removed, make the
object available for garbage collection. It does not cause the object
to be destroyed.

And as Armin said, please don't use arrays for this. List (Of T) is
much better.

On Tue, 28 Oct 2008 23:57:20 -0400, "Miro" <mi**@beero.com wrote:
>Its vb 2008

Thank you for the post.
I was under the impression - since I am 'sitting' in the object still during
_FormClose then I cannot Remove my object from underneith my feet.

Im assuming then by your statement
>>The object on which the current method is executed is never destroyed.
That once I leave the form and it does close - it will be destroyed in the
background - I dont need to run anything else?

I will google and search up "List" to use a list instead of an array.

Thank you,

Miro

"Armin Zingler" <az*******@free net.dewrote in message
news:ub******* *******@TK2MSFT NGP02.phx.gbl.. .
>"Miro" <mi**@beero.com schrieb
>>where do i actually remove the array element when the form is
closed. I do not want it to stay in the array.

Do yourself a favor and use a List(Of frmMyTestForm) instead of the array.
(which VB version?) Safes you from item shifting and redimming.
>>I do not think I can do it in the _FormClosed of the
frmMainScreen .frmFormsOpen(L engthOfGames)._ FormClosed
because I am actually in the form itself still - so I am assuming I
cannot kill the object when I am still using the object.
( im trying to kill myself from myself ).

You don't kill anything by removing one reference. You can safely remove
the
item from the list in the FormClosed event. The object on which the
current method is executed is never destroyed.
Armin
Oct 29 '08 #6
Thank you -
I have changed it to use the List(Of T) and it works great and 10x easier.

I used an array because of my old dos day programming - arrays is all we
had.

Miro

"Armin Zingler" <az*******@free net.dewrote in message
news:ej******** ******@TK2MSFTN GP03.phx.gbl...
"Miro" <mi**@beero.com schrieb
>Im assuming then by your statement
>>>The object on which the current method is executed is never destroyed.
That once I leave the form and it does close - it will be destroyed in
the
background - I dont need to run anything else?

Yes, nothing else is required.
>I will google and search up "List" to use a list instead of an array.

Not required to google - look in the object browser. It's
System.Collecti ons.Generic.Lis t(Of T)

see also:
http://msdn.microsoft.com/en-us/library/41107z8a.aspx
Armin
Oct 30 '08 #7
I see,

I was the understanding that if i say
dim bla as new form1

then I was under the impression the object instantiated and the object
exists in bla which was dim'd here.

To 'remove' it from this 'dim' would be pulling the rug from under me.

As I understand your comment - the object "REFERENCE" is dim'd here, but the
actaul object exists somewhere else, so I can
"undim" my bla without worries. ( if undim was a word ) but basically
remove it from bla.

Miro

"Jack Jackson" <jj******@cinno vations.netwrot e in message
news:sj******** *************** *********@4ax.c om...
You are confusing removing a reference to an object from a list with
destruction of the object.

An object can have many references. Removing those references does
nothing other than, when all references have been removed, make the
object available for garbage collection. It does not cause the object
to be destroyed.

And as Armin said, please don't use arrays for this. List (Of T) is
much better.

On Tue, 28 Oct 2008 23:57:20 -0400, "Miro" <mi**@beero.com wrote:
>>Its vb 2008

Thank you for the post.
I was under the impression - since I am 'sitting' in the object still
during
_FormClose then I cannot Remove my object from underneith my feet.

Im assuming then by your statement
>>>The object on which the current method is executed is never destroyed.
That once I leave the form and it does close - it will be destroyed in the
background - I dont need to run anything else?

I will google and search up "List" to use a list instead of an array.

Thank you,

Miro

"Armin Zingler" <az*******@free net.dewrote in message
news:ub****** ********@TK2MSF TNGP02.phx.gbl. ..
>>"Miro" <mi**@beero.com schrieb
where do i actually remove the array element when the form is
closed. I do not want it to stay in the array.

Do yourself a favor and use a List(Of frmMyTestForm) instead of the
array.
(which VB version?) Safes you from item shifting and redimming.

I do not think I can do it in the _FormClosed of the
frmMainScree n.frmFormsOpen( LengthOfGames). _FormClosed
because I am actually in the form itself still - so I am assuming I
cannot kill the object when I am still using the object.
( im trying to kill myself from myself ).

You don't kill anything by removing one reference. You can safely remove
the
item from the list in the FormClosed event. The object on which the
current method is executed is never destroyed.
Armin
Oct 30 '08 #8
If I only had your brain to pick before I start to code :-)

Thanks,

Miro

"Cor Ligthert[MVP]" <no************ @planet.nlwrote in message
news:uJ******** ********@TK2MSF TNGP06.phx.gbl. ..
Miro,

You can find all the mdi forms by using
\\\
me.MDIParent.MD IChildren
///

http://msdn.microsoft.com/en-us/libr...ichildren.aspx

Probably much easier,

Cor
"Miro" <mi**@beero.com schreef in bericht
news:Os******** ********@TK2MSF TNGP03.phx.gbl. ..
>>I have created myself an issue, and perhaps my idea wasn't as bright as I
thought it was originally.
If someone can help me figure out what the correct train of thought
should be - or if there is a solution to this one.

I created a dummy mdi app.
In the main form ( frmMainScreen ) I created a variable as such:
<written in notepad to trim everything down>

Public Shared frmFormsOpen() As frmMyTestForm

Now, in a totally seperate sub form opend from the main form I do this on
a button click:

LengthOfGame s = (frmMainScreen. frmFormsOpen.Le ngth - 1)
ReDim Preserve frmMainScreen.f rmFormsOpen(Len gthOfGames)

frmMainScreen. frmFormsOpen(Le ngthOfGames) = New frmMyTestForm
frmMainScreen. frmFormsOpen(Le ngthOfGames).Md iParent = Me.MdiParent
'Remember that this form is also an mdi child of the main form.
'Set my own property for later use
frmMainScreen. frmFormsOpen(Le ngthOfGames).Ga meID = anIntegerValue

frmMainScreen. frmFormsOpen(Le ngthOfGames).Sh ow()

'Works Great
So in other code on other child forms forms I can do stuff like this:

For Each SearchForm As frmMyTestForm In
frmMainScreen. frmFormsOpen
If SearchForm.Game ID = mytestID Then 'mytestID is set to a
value from something else
SearchForm.Brin gToFront()
Exit For
End If
Next
My problem is this:

where do i actually remove the array element when the form is closed. I
do not want it to stay in the array.
I do not think I can do it in the _FormClosed of the
frmMainScreen. frmFormsOpen(Le ngthOfGames)._F ormClosed
because I am actually in the form itself still - so I am assuming I
cannot kill the object when I am still using the object.
( im trying to kill myself from myself ).

That is my issue I have created myself and I was wondering if someone can
point me in the right direction on how to get around this issue.

Thanks,

Miro

Oct 30 '08 #9
Making a variable no longer point at an object does not "pull the
rug". When all references to an object go away, the object becomes
eligible to be garbage collected at some time in the future.

Forms are a little different in that the framework keeps track of them
and has a reference to all open forms (Application.Op enForms), so even
if you clear your reference there is still one being held by the
framework.

For example:

Public Class MyClass
Public A As Integer = 0
End Class

Dim x As New MyClass ' There is one reference to an instance
' of MyClass
Dim y as MyClass = x ' Now there are two references
' to the instance
x = Nothing ' Now there is one reference (y)
y = Nothing ' Now there are no references and
' the instance is eligible for garbage
' collection.

On Thu, 30 Oct 2008 10:59:30 -0400, "Miro" <mi**@beero.com wrote:
>I see,

I was the understanding that if i say
dim bla as new form1

then I was under the impression the object instantiated and the object
exists in bla which was dim'd here.

To 'remove' it from this 'dim' would be pulling the rug from under me.

As I understand your comment - the object "REFERENCE" is dim'd here, but the
actaul object exists somewhere else, so I can
"undim" my bla without worries. ( if undim was a word ) but basically
remove it from bla.

Miro

"Jack Jackson" <jj******@cinno vations.netwrot e in message
news:sj******* *************** **********@4ax. com...
>You are confusing removing a reference to an object from a list with
destruction of the object.

An object can have many references. Removing those references does
nothing other than, when all references have been removed, make the
object available for garbage collection. It does not cause the object
to be destroyed.

And as Armin said, please don't use arrays for this. List (Of T) is
much better.

On Tue, 28 Oct 2008 23:57:20 -0400, "Miro" <mi**@beero.com wrote:
>>>Its vb 2008

Thank you for the post.
I was under the impression - since I am 'sitting' in the object still
during
_FormClose then I cannot Remove my object from underneith my feet.

Im assuming then by your statement
The object on which the current method is executed is never destroyed.
That once I leave the form and it does close - it will be destroyed in the
background - I dont need to run anything else?

I will google and search up "List" to use a list instead of an array.

Thank you,

Miro

"Armin Zingler" <az*******@free net.dewrote in message
news:ub***** *********@TK2MS FTNGP02.phx.gbl ...
"Miro" <mi**@beero.com schrieb
where do i actually remove the array element when the form is
closed. I do not want it to stay in the array.

Do yourself a favor and use a List(Of frmMyTestForm) instead of the
array.
(which VB version?) Safes you from item shifting and redimming.

I do not think I can do it in the _FormClosed of the
frmMainScre en.frmFormsOpen (LengthOfGames) ._FormClosed
because I am actually in the form itself still - so I am assuming I
cannot kill the object when I am still using the object.
( im trying to kill myself from myself ).

You don't kill anything by removing one reference. You can safely remove
the
item from the list in the FormClosed event. The object on which the
current method is executed is never destroyed.
Armin
Oct 30 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3011
by: Willem van Rumpt | last post by:
Hi all, coming from an unmanaged programming background, I took my time to sort out the IDisposable and finalizer patterns. Just when I thought I had it all conceptually neatly arranged, the "Close()" methods reared their ugly (at least it would seem...)heads. I was happily delving away in the .NET framework, investigating the stream classes with the msdn and Lutz Roeder's .NET reflector, when I stumbled upon the following:
10
6280
by: Jim H | last post by:
I sometimes get the following error from my Form's Dispose Method when the application is closing: ------------------------------------------------- An unhandled exception of type 'System.InvalidOperationException' occurred in system.windows.forms.dll Additional information: Cannot call Dispose() while doing CreateHandle(). ------------------------------------------------- How do I find out what is calling CreateHandle()? Here is the...
19
3875
by: Nathan | last post by:
I know this has been asked previously, but I've run into a situation where I need to know the difference between close and dispose, and I can't get the information I need from msdn help or previous posts. I have a game form that has a timer, which runs as long as the game is being played. When the timer reaches zero, the GameOver form is called. On the game form is a Quit button, in whose click event I have only the command "Me.Close"....
35
11403
by: Eric Sabine | last post by:
In my Finally block, I was using cn.close (where cn is an ADO.NET connection object, SQLConnection to be exact) and then I came across the following in some microsoft code. If Not cn Is Nothing Then CType(cn, IDisposable).Dispose() End If I have to admit, I'm not sure what happens here. Will someone explain this line of code (the middle one, not the if statement LOL) to me please?
8
1898
by: Paul W | last post by:
Hi - in an asp.net application, how should I close out a sqlclient.connection? What combination and order of Conn.close conn.dispose conn=nothing Should I use? Specifically, is the .dispose required? Thanks,
3
9834
by: Joris De Groote | last post by:
Hi, I use Adobe Acrobat to read tekst from PDF files. After that the file has been read, I move the file in a folder (using the date I got from the text I got from Acrobat). Now here is my problem. When I want to move the file, I get an error stating: System.IO.IOException: The process cannot access the file "x:\VF\2006-01\CVF-06000007.pdf" because it is being used by another process.
54
5202
by: Zytan | last post by:
I have a log class that makes a synchronized TextWriter like so, in the constructor: StreamWriter sw = new StreamWriter(filename); tw = TextWriter.Synchronized(sw); In the destructor, ~MyLogClass(), I call: tw.WriteLine("some stuff"); tw.Close();
6
1615
by: RFleming | last post by:
I am a pretty experienced VB programmer trying to make a jump to C#. I have created a simple (so I thought) project and seem to be stuck. I know I can create a form and write the code within the form. However just for the experience I created a Main class and created an instance of frmMain. Using the designer I created a button btexit. When the button is pushed I am trying to dispose the loaded instance of frmMain. I am getting the...
10
1131
by: Miro | last post by:
I have created myself an issue, and perhaps my idea wasn't as bright as I thought it was originally. If someone can help me figure out what the correct train of thought should be - or if there is a solution to this one. I created a dummy mdi app. In the main form ( frmMainScreen ) I created a variable as such: <written in notepad to trim everything down> Public Shared frmFormsOpen() As frmMyTestForm
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7721
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4366
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4615
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.