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
10 1136
Thank you - excellent example for me to understand. -makes perfect sense
now.
I appreciate your time.
Thank you again,
Miro
"Jack Jackson" <jj******@cinno vations.netwrot e in message
news:64******** *************** *********@4ax.c om...
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 _FormClos e 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 backgroun d - 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**** **********@TK2M SFTNGP02.phx.gb l... "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 >frmMainScr een.frmFormsOpe n(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 >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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:
|
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...
|
by: Simon Harris |
last post by:
Hi All,
Do I need to use both Conn.Close() & Conn.Dispose() when I have finished
with an SQL connection?
--
I am using the free version of SPAMfighter for private users.
It has removed 2425 spam emails to date.
Paying users do not have this message in their emails.
|
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"....
|
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?
| |
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,
|
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.
|
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();
|
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...
|
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
|
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...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
|
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,...
|
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...
|
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |