|
-
Jan 27th, 2004, 04:34 AM
#1
Thread Starter
Evil Genius
#Region's
Hi everyone,
In the past, I've always left the generated #region part of a vb.net app, but I've just realised it's a good way of grouping functions which I want to hide.
I've got the following code in several of my classes - 2 or 3 procedures which would be to hide / collapse & move out of the way at once.
As I can't find diddly squat on custom #regions on the net, I want to ask if this is good practice or not? will the GC read the procedures ok if their held within a custom region? Thanks!
VB Code:
#Region "CleanupCode"
Public Overloads Sub Dispose()Implements IDisposable.Dispose
'Some Code Here
End Sub
Protected Overrides Sub Finalize()
'More Code Here
End Sub
#End region
-
Jan 27th, 2004, 04:47 AM
#2
I do this as well. I've had no problems with the GC not finding stuff in a hidden Region.
This world is not my home. I'm just passing through.
-
Jan 27th, 2004, 08:17 AM
#3
yay gay
Everything starting with a # is a preprocessor directive..in #Region's case it means that it will just be ignored by the compiler, but will help IDE's provind the hide code functionality. If you think about it I wouldn't see a SINGLE good thing in creating members that would be hidden from the GC? What were you thinkin of? Why to have functions that wouldn't be compiled/read/whatever?
\m/  \m/
-
Jan 27th, 2004, 08:40 AM
#4
Thread Starter
Evil Genius
That's what I was after, some kind of explanation as to what the #region's are.
I've just modified the framework garbagecollection sample & placed several of the disposed / finalize methods in regions & put extra writelines in to test that last theory & it seems to see them okay...
-
Jan 27th, 2004, 08:55 AM
#5
Thread Starter
Evil Genius
I've just been doing some testing and kind of answered 1 point there, the region code compiles & runs okay like this:
VB Code:
Public Class Class1
implements IDisposable
#region "Test"
Public Sub New()
console.WriteLine ("Created")
End Sub
Public Overloads Sub Dispose() implements IDisposable.Dispose
GC.SuppressFinalize(Me)
console.WriteLine ("Disposed")
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
console.WriteLine ("Finalized")
End Sub
#End region
End Class
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim x as New Class1
x.Dispose
x = nothing
End Sub
Private Sub Button2_Click1(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Dim x as New Class1
ActiveForm.Dispose
End Sub
Can anyone please provide a link or explanation of when to use regions, their purpose etc. though as I'd like to know more about them. Cheers!
-
Jan 27th, 2004, 09:05 AM
#6
Regions are just ways of grouping related code in the editor - they have no impact on the compiled program.
My own preference is to have a region for public constructors, methods, events etc. so the code looks like the help file...
-
Jan 27th, 2004, 09:33 AM
#7
PowerPoster
To prove there is no impact, look at the visual studio created code when you design a form. It is all included in a region, but runs like normal. Regions ONLY allow you to collapse code groups to help you manage large amounts of code. It does ABSOLUTELY NOTHING other than collapse and expand code that you put inside it.
That is it. There should be no more discussion about this.... This is actually silly this topic went this far.
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
|