Call Dispose On All Items Delcalred And Used Within A Procedural Scope?
Aug 31, 2009
I am having trouble understanding the proper implementation of Dispose. While I totally understand the IDEA behind it (Ensuring that variable references to objects are released and free to be GC'd), I am not sure I am doing this properly.I try to call dispose on all items delcalred and used within a procedural scope when I am done with them (or even better, employ a Using block).When I declare Class-level items, I assume I should call dispose on them prior to destroying the class (During the "Disposed" event, right? which will occur when "Dispose" is called on my class?).As Declared in Class-level Declarations:
Public Class MyDisposableClass
Implements IDisposable
Protected mImgExpand As Image = My.Resources.ListCollapsePNG9x9_DK[code]........
When THIS class is instantiated within another class (Say, a form),I call "Dispose" on THie instance of this class during the form's "Close" Event. Everything seems to work fine. However,when I step through the code, things seem to go in a circle. We go from the close event, which calls dispose on the class instance, to the class instance dispose event, then back to the parent class disposed event, etc.
View 7 Replies
ADVERTISEMENT
May 18, 2012
I'm trying to fix all my project warning according to Microsoft code analysis (CA:XXXXX) One of the warning is "CA2000: Dispose objects before losing scope" My Code is:
[Code]...
View 2 Replies
Dec 4, 2011
I want to create a new instance of a class when I click on a button, but I need to interact with members of that class using other controls on the form, so I need the class to have a global scope. I know I could call the new class in formload, but the class creates certain variables that need to be current. If it is done on formload, the variables wouldn't be current, because if the class is created at formload, it would have different info at that time. Surely, there must be a way to create an instance of the myClass from within a sub that is accessible from other subs of the same class.
[Code]...
View 2 Replies
Jun 22, 2011
When you set a region equal to another, or set it equal to a new instance, do you have to call dispose on the region, or does VB do that? (I guess this isn't necessarily specific to regions)
ex:
'at some point in the code a region is created
Dim Rgn as New Region(SomeRect)
'....
[Code].....
If Rgn now points to the Rgns(0) clone, what happens to the original memory created by "New Region(SomeRect)"? Do I need to call dispose on Rgn before assigning it to the the Rgns(0) clone?
View 4 Replies
May 14, 2010
Should I call .Dispose() after returning an object that implements IDisposable? [code]In other words, is the object I return a copy, or is it the object itself?
View 11 Replies
Sep 16, 2009
In my Zeal to get with the "Dispose" program, I implement a dispose pattern (still learning the ways and means of THAT) wherever it seems to make sense.I THINK I have the basic idea. However, I notice that, while Drawing.Brushes HAVE a Dispose method, when I call it, some sort of instability is created in Visual Studio itself, and i get the dreaded "Visual Studio has encountered an error and needs to close" splash screen, with no useable error information. SHould I assume that one should just NOT call dispose on Brush objects, or is there something I am missing here: [code]
View 7 Replies
Jul 22, 2010
say you have a sub containing an io.streamwriter. That streamwriter is declared and used only inside that sub (and not as static). Should you still call dispose on that streamwriter or is it disposed automatically as it is no longer in use after that sub, until you call that sub again?
View 2 Replies
Oct 14, 2009
I have 2 question, hope somebody give me an explanation: 1. Should a local variable call dispose method and set to nothing? 2. If some method have an arguments which it is a ByVal argument, it means a method create a new object? But If it is a ByRef argument, it means a method don't create a new object?
View 4 Replies
May 17, 2010
I have and still do program principally in a procedural manner. I've never created objects or ever used the OOP paradigm. I understand the concept certainly, and know generally how it works but have never implemented it. I presume this leaves me though with limited options in the future as OOP is and has been all the rage, especially now that VB.Net is full OOP. Event still, I've written both ASP.Net and VB.Net applications without using OOP, or not that the product didn't create itself.It appears I am not alone either, there seems to be a number of people far more intelligent and experienced than I that eschew OOP.
[URL]
View 1 Replies
Nov 12, 2009
Does calling the Dispose method on a Windows.Forms.Timer call it's Stop method? Or should I stop the timer before I dispose it?
View 5 Replies
Feb 27, 2009
Our company currently uses an APL model to illustrate our life products. We are in the process of converting this to Excel/VBA because the APL system is extremely difficult to maintain.APL is difficult to maintain because the code has become over the years (~15yrs) spaghetti and only a select people (who have worked here 5+years) really understand this to make updates when new products come out. APL is also not well known and difficult to understand. I just would like help on designing the system, my main career is not a programmer, and the design I was envisioning was a "Procedural" approach. (the APL is procedural rather then object oriented. I have not used object oriented code before)Basically the program illustrates a life insurance product. That just means it projects a fund out from the time the policy is issued to age 120. The illustration is given to the policyholder as a way of predicting what the value of their fund will be given some assumptions.The program does the following1.) Populate Variables2.) Calculate Premiums Types3.) Monthly processing4.) Output values to spreadsheetThe system has to illustrate different types of Products and we are adding new products to the system. Most of the main structure of the program (in VBA) is already written. It seems that (#3) monthly processing will vary by product, and I would like help with maintaining that part of the code. The other 3 parts of the program are not a problem maintaining.We will be continually adding products. We will start with about 5 products and maybe add about 5 per year.Here is the Monthly Processing code:... Call MonthlyProcessing(120, PremPayMode0, Assump0, True, DumpLumpSum0)
View 4 Replies
Jun 25, 2012
I looked at the Dispose() method in System.Data.SqlClient.SqlTransaction (using a decompiler):
[Code]....
Why does everyone say in forums that it is Rolling back in the dispose? Where does it rollback?
View 1 Replies
Jul 2, 2009
I'm probably missing out on something fundamental here but it seems rather tricky and confusing to me so here goes.to demonstrate the issue I have the following example .aspx page
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
[Code]...
View 3 Replies
Jun 18, 2012
Am looping a list object. The list contain 18 object. The loop running 18 times but the end of the 18th one getting Object reference not set to an instance of an object..
@For Each Slogs As SFAMobile.MobileServices.CustomerDetail In Model.Customers
@<option value='@Slogs.CustomerId' @selectedVal >@Slogs.Name ( @Slogs.CustomerId ) </option>
Next
View 2 Replies
Aug 31, 2010
I have been working on a VB app to edit an excel document. I want to keep my excel workbook in scope for the whole app.
For example here is how my program looks now
private sub
open workbook
end sub
private sub
reference workbook
end sub
I want a way to just call my workbook at the top and have all of my subs recognize it. I guess like a global variable or something.
[URL]
View 5 Replies
Feb 27, 2009
Does VB.NET have any scope nesting operators like {} in C type languages? Example C++ type code:
int i;
i = 0;
{
int i;
i++;
}
View 2 Replies
Dec 16, 2011
ok I have two procedures:This is for the tick of a timer
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
intTickCounter = intTickCounter + 1
[code].....
View 4 Replies
Jun 12, 2011
how to declare scope for variables outside their class?
Here's what i have in a class known Create_User:
Public Class Create_User
Public conn As New SqlConnection(My.Settings.HotelConnectionString)
Public usercmd As SqlCommand
[Code]....
How can i increase the scope of these variables to be used in another class? I dont want to keep declaring them again and again.
View 4 Replies
Aug 17, 2010
[code]In the above code what will be state of 'conn' variable and the 'cmd' variable and the State of the Connection to the DB in the following two case
i. Me.Close line
2. If any error occurs
View 3 Replies
Jun 7, 2011
I'm moving from VB6 to VB.net and there are a few things confusing. In vb.net, your program just automatically has a form, now the form in in a class and so it may or may not be there. In vb6, the main subroutine controls program flow and I don't see that in vb.net. However, my biggest problem is that I have a com dll that has a connect class with events. I need to be able to access these variable outside of that class. I don't understand how to do that. I can't seem to declare public withevents outside of the class and in the namespace so it can be shared with other code. Its say "not valid" in Namespace.
So what is the best way to do that. Do I create a set/get property for the class that holds this value? And, if I do that, is the connect class automatically instantiated as a part of the COM dll? Right now I don't instantiate the connect class, I assume the application does. But I'm not sure exactly how the property of the class would be set...perhaps I would need to call the property set from the on-connection method. Anybody know what the answer to these two questions are and this 3rd one? How can I have a variable that has "events" have scope across the entire project?
View 3 Replies
Jan 21, 2010
While DataReader.Read
Dim Foo as New FooBar
Foo.Property = "Test"
Loop
In VB.net, does this create a new Foo instance every for every loop? Or just one Foo instance with block level scope? Do all blocks (If..EndIf, For..Next) work the same in this regard?
View 3 Replies
Mar 19, 2012
I am writing an App that automates file uploads from users desktops to a specified file server. On the first run of the app, I need the user to select a file server and save it for all other users of that PC. I thought I could do this
with application settings but it appears it is not suitable for this purpose. I need suggestions on how I can make this work.
I thought about a registry setting but the user may not have permission to edit the registry based on group policy/security settings.
I also thought about creating an XML file with the file server name that I can read from the installed project directory, but I was hoping there was a more streamlined way.
View 14 Replies
Apr 5, 2011
Below is example code of what I want to do:
Public Class Test
Sub New()
Dim cool As New B
cool.Doit()
[code]....
View 6 Replies
Nov 22, 2011
I am porting php code to vbnet (i'm a little better at vbnet than c#). In the php is the scope resolution operator.
Here's the bit:
$args = phpZenfolio::processArgs( func_get_args() );
Equivalent in c#/vbnet?The whole function is the following which i gues is equivalent to the sub new in vbnet.
public function __construct()
{
$args = phpZenfolio::processArgs( func_get_args() );
$this->APIVer = ( array_key_exists( 'APIVer', $args ) ) ? $args['APIVer'] : '1.4';
[code]....
View 2 Replies
May 17, 2012
I have a Function for checking the input in a textbox and only allowing Numeric & Backspace; everything works fine so far. My form is for financials and it has about 20 textboxes; they all receive Numeric only data; there is NO alpha data on the entire form required. Note in the snippet below that I don't even need a decimal point as well.
Is there a way to handle ALL textboxes on this form without having to place the Function call in each textbox KeyPress event. took a long (5 year) hiatus from developing VB6
Public Function TrapKey(ByVal KCode As String) As Boolean
If (KCode >= 48 And KCode <= 57) Or KCode = 8 Then
TrapKey = False
[Code].....
View 5 Replies
Aug 23, 2009
I have a public variable which seems to be going out of scope. I am confused as it has been dimensioned as a public variable: Public xlCell as As Microsoft.Office.Interop.Excel.Range
I originally had all my code in the same module in the same project and it was wrapped within a For/Next Loop (Example 1). I decided to clean up my code and make it more modular (Example 2). All the code is still in the same module in the same project.
Upon doing so, my public variable is not recognized in any of the private subs that I have created. I keep getting the following error: Message="Object reference not set to an instance of an object." When I test the variable using ?IsNothing(xlCell) in the Main Sub I get False in the main sub. this tells me te variable is recognized. However as soon as the Call SelectCaseSub() is triggered, I get a True value for ?IsNothing(xlCell). Why is this? Shouldn't this variable be in scope regardless?
[Code]...
View 6 Replies
Nov 28, 2011
I have a complex Regex which is used to help strip out HTML from user input. I'm aware that .NET caches static Regex calls to some extent, but this one is big and used frequently, so I'd like it to hang around.[code]...
View 1 Replies
Apr 7, 2009
I've got a simple function that takes a List parameter. While working with it, it copies it and reverses the copy using .NET's List(Of T).Reverse method.
[Code]...
View 6 Replies
Nov 10, 2009
I am trying to acccess a Collection in another form
vb
MsgBox(frmNetworkTest.servers.Count)
What I do this from the same form, I get 16, but when I run this code from a different form, I get 0.The variable is declared public.
vb
Public servers As New System.Collections.ArrayList()
View 5 Replies
Mar 15, 2011
I'm trying to create a simple media player that will scan a directory for certain filetypes, add them to a playlist then play a random playlist entry - changing every x seconds.I figured this would be simple in VB and, to an extent it was. I have the code running that chooses the directory and plays the random file.I just need to now make this repeat every 30 seconds or so.I have all the coded attached under the sub for the 'open' function of the player so it's quite flat. I think I need to use a timer here, to trigger the routine to pick and play the media every 30 seconds?In doing this I think I need to break the variables out of the function I currently have as they need to be shared between the timer loop function and the central 'creating file list' function.
I'm having trouble - I'm no coder (as you'll tell!) and although getting this far was easy I'm now (I think) bumping into threading / variable scope issues which are a bit of a brick wall.I've tried making the variables public / global by declaring in the class rather than the sub but I get errors at runtime. Presumably because of how I'm creating the windows media objects? [code]
View 8 Replies