Asp.net - Does Retyping And Declaring Variables That Could Otherwise Be Inherited Degrade Performance
Feb 7, 2012
I'm wondering about the performance differences between imports and inherits in a .net app.I currently program by creating multiple classes that logically define my objects. e.g. a class for customers, users and product.When i want to use these classes in a page i have to import them eg. "Imports Custmomers" and then later in my code i have to create a variable and datatype it before i can use the sub routines and functions from class.I understand from a coding perspective this keeps it all neat and tidy.So my question Would it be not better to combine all my classes into a base class, inherit that base class, rather than import it, when i want to use it and so cut down on the extra declarations and associated code that come from importing a class; and if i did this would it aid performance?
View 1 Replies
ADVERTISEMENT
Jan 7, 2010
Does the memory used in declaring variables are reclaimed by the OS when these variables go out of scope?Does the memory used be released by setting thier value to nothing? if not, then how can I force the garbage collector to run or excecute at a certain/desired time..How about in Windows Forms..How can we make sure that the memory used in initializing and showing forms be released if those forms were closed?
View 13 Replies
Jul 26, 2010
I actually came from VB6 and starting to learn VB.NET. I saw this line of code which I cannot understand how it works nor how it goes.
Private MAX_VALUE As Integer = (1 << 14)
View 2 Replies
Oct 6, 2011
I have just been experimenting with nesting classes within a User class I had already created.
E.g.
Friend Class User
[Number of Properties...]
Friend Class Address
[code]....
I get the same error message!!! "Declaration expected". Also I notice the variable's name is not coming up in intellisense. I have not come across this before as declaring an using variables and objects has been straight forward up until now.
View 2 Replies
Sep 29, 2011
The user clicks a button, a new form is generated where the user enters his/her password? How can I keep an in-memory copy of the username?
For instance in web forms, I can just use Session ("User"). How can I replicate this with winforms?
View 3 Replies
Sep 23, 2011
I've created a 30 point wizard. Every step gathers between 1 and 3 variables. I've created a module and publicly declared the variables there. At the end of the wizard, one master form opens, gets all the variables, and displays them on one form. At this point calculations are run too which populates more variables. This works fine for one instance of the process.
the user may want to be running two instances of the wizard at once. Obviously, if the previous wizard is part complete and they start a new one, the variables are going to get crossed or replaced by the new wizard.Is there a way for the variables to be declared publicly but used in multiple instances?
View 8 Replies
Oct 25, 2010
OK, I'm working on a project and i need to access the property of a usercontrol which I have set.Here is the code in the UserControl
Private Color As Color = ColorTranslator.FromHtml("#000000")
Public Property InkColor() As Color
Get
[code].....
View 4 Replies
Mar 5, 2010
What's the proper way to declare variables in a class? I've been doing something like:
'in a class
public shared teststring As String = "first"
'on a code behind
[Code]....
with shared variables loading a second window or reloading the page (without clicking the button) renders the hello world string. so how do I declare variables in a class but make it per instance?
View 5 Replies
Oct 15, 2009
When I am writing a sub or function that does some calculations etc. I often need a loop or a integer variable to count.
An example:
''' <summary>
''' Compare elements with the new data and perform all necessary actions.
''' </summary>
[Code]....
As you can see, variables like timespan, nullCount and seconds are declared within this sub.
My question is, is it better to declare these in the class? I can imagine that would boost performance.
View 8 Replies
Jun 25, 2011
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim chatters As List(Of Chatter) = New List(Of Chatter) chatters.Add(New Chatter(New Guid("CD863C27-2CEE-45fd-A2E0-A69E62B816B9"), "Me")) chatters.Add(New Chatter(Guid.NewGuid, "Juan")) chatters.Add(New Chatter(Guid.NewGuid, "Joe")) Application.Add("Chatters", chatters)
[code]....
I am unable to understand last 3 lines that are bold and underlined. Please what is hppening here. Chatter and Chat are two classes defined in App_Code folder. Is there any sight that contains all possible ways to declare and initilaze variables and data structure:
Dim chatters As List(Of Chatter) = New List(Of Chatter)
View 1 Replies
May 11, 2009
I need to write a simpe calc. program to add, mutiply, subtract and divide. I want to have two textboxes that I enter numbers in and when I click a button, +,-,/ or * a third text box will display the result.Rather than declaring my variables inside each instance of a click event I would like to declare them globally so I just need to perfom the calculation on them and display result. However declaring them globally doesn't work for me. I;ve tried the variables inside the btnAdd click event which works, but as I said I'd prefer to declare them onece globally.
Public Class Form1
Dim number1 As Double = CDbl(txtNum1.Text)
Dim number2 As Double = CDbl(txtNum2.Text)[code]...
View 1 Replies
Dec 8, 2009
recently started converting our project from 1.1 to 2.0
It was fine with the following:
Public ghtAllAppMsgs As New Hashtable(300)
Now it is complaining to change to the following is this the right way:
Public ghtAllAppMsgs As New System.Collections.Hashtable(300)
This is under global.vb class file: here are the imports i already had in this file:
Imports Microsoft.Web.UI.WebControls
Imports Microsoft.Web.UI.WebControls.MultiPage
Imports System.Web
[Code]......
View 1 Replies
Mar 23, 2012
I am writing a program and i need to declare matrices but there will be a different number to declare everytime the program is run so I was wondering if anyone knew how to declare them inside a for loop
eg.
For i = 1 to NumberOfMatrices
Dim matrix i (5,5) As Double
Next
View 4 Replies
Feb 11, 2009
I am new to the forum and new to the visual studio set up and have been working at a practical at home and have ran into some difficulty. The notes say that I am to declare several module variables below the section entitledI have the rest of the form complete but have been unable to locate where I am to place this code
View 1 Replies
Nov 5, 2010
I am at a loss to figure out why this code results in 2 errors when I try to Parse it inthe SSMS.
@Collection varchar = Books,
@Title varchar = 0,
@Authors varchar = 0,
[Code].....
I think that I re wrote this query ten times todaday and continue to get errors and don't know what my problem is
There are underlines in red under the 0 in the BookLoanStatus and under all of the parameters in the SQL.
View 2 Replies
May 26, 2010
I am new to Visual Studio.NET but very familiar with the old ASP (using DreamWeaver).I am unfamiliar with this system of having seperate files for VB code and HTML, in my Visual Studio project I have a Default.aspx file and a Default.aspx.vb file. Now I want to declare a variable that will be accesible to all my functions on the Default.aspx.vb file. I.e. if a user clicks on one button and it launches a Protected Sub called Button1_Click, I want that button to be able to read or write to that variable and then if a user clicks on another button, I want it to likewise be able to read and write to that variable.So where should these variables be dimmed?
At the top of the aspx.vb file? Before or after the line that says "Partial Class _Default"?Or at the top of the aspx file? (Within <% %> brackets?)
View 3 Replies
Jan 6, 2011
Is it possible for a class of exposing a type for function returns, without allowing users of that class to create variables of that type? A couple usage scenarios:A Fluent interface on a large class; a statement like "foo=bar.WithX(5).WithY(9).WithZ(19);" would be inefficient if it had to create three new instances of the class, but could be much more efficient if the WithX could create one instance, and the other statements could simply use it.A class may wish to support a statement like "foo[19].x = 9;" even when foo itself isn't an array, and does not hold the data in class instances that can be exposed to the public; one way to do that is to have foo[19] return a struct which holds a reference to 'foo' and the value '19', and has a member property 'x' which could call "foo.SetXValue(19, 9);" Such a struct could have a conversion operator to convert itself to the "apparent" type of foo[19].In both of these scenarios, storing the value returned by a method or property into a variable and then using it more than once would cause strange behavior. It would be desirable if the designer of the class exposing such methods or properties could ensure that callers wouldn't be able to use them more than once. Is there any practical way to accomplish that?In formulating a question, it's difficult sometimes to draw the line between complicated usage cases, and simpler usage cases which aren't quite so important. Here's another usage case, and one closer to the one I'd be most interested in (though I'm also interested in Fluent chaining; being able to have something behave like a C++ reference to a value type would be nice, but probably too much work to bother with).I have a type which is somewhat like the Windows registry, in that it is a hierarchical collection of items, each of which may have a string value, an integer value, and/or a nested collection of items. I wish to be able to support the following types of usage:[code]As for the Fluent interface, my thought would be to have the WithXXX properties return a new instance of a derived class which shadows (not overrides!) the WithXXX properties with versions that simply modify the current instance. The return object from WithXXX would be known to be of the derived class, and would thus use the shadowed WithXXX methods, but once it was assigned to a variable, it would be regarded as an instance of the base class, so the next WithXXX would create a new instance.
C++ a stronger concept of value types than C# or vb.net, including the very useful concept of references to value types; it ensures that references to value types cannot be persisted outside the scope of the type in question. Unsafe code in C# can use pointers to value types, but they don't have the protections offered by C++ references.
View 3 Replies
Jun 3, 2009
In re-engineering a windows forms application, I find that a lot of code-behind in the various form classes is duplicative and I'm trying to centralize as many procedures as possible into a base class which can be inherited and used by the subclassed forms.
This process seems to be going well and is making the code in my subclasses much simpler and hopefully easier to maintain, but I'm not sure where to draw the line between leaving code in the subclasses and engineering for generic resusability and moving it to the base class.
Specifically, in some subclasses I have code which manipulates variables and objects specific to the subclass, and although I could move the code-behind into the base class, the base class code references specific objects which are needed to compile. For example, each subclass manipulates a databound datagridview and form detail controls which allows the user to select between multi-record and detailed single-record views of a datatable.
In Visual Basic 2008 do I need to declare dummy data objects in the base class so that the base class will compile? Or is there a way to indicate that the data objects will be provided by the subclass?
View 13 Replies
Jun 8, 2009
I came across a number of new Private Shared variables (of type Hashtables(Of String), initialized in the declaration) added to a partial class for a very large (DataContext-derived) class. This seems sensible to me in one sense because they never change, and making these shared variables ensures that they won't get re-initialized every time a function is called. However, these variables are only used within the scope of one function in the class, and I fear the private namespace of this DataContext-derived class is getting rather polluted, and having these sorts of things exposed at such a high level might be confusing to others reading the code in the future.
Would there be negative performance impact to making these local variables within the function where they are used, or is there some better way to handle this? Basically we are using these 3 hashtables to determine whether anything within particular subsets of properties changed (using GetModifiedMembers and then using the Overlaps function of the hashset to see if any of the modified members correspond to members we care about).
Edit: I caved and took the time to write my own test program, which confirmed that there is a cost to using local variables (which I assume applies generally to all cases -- I doubt there's any case where a shared variable would be slower unless using the shared variable requires some additional logic to do so properly): [Code]
So in this particular case, using the local variable costs about 200%. But in most cases (including my own), the time is probably negligible compared to the overall task. So I guess the question now becomes, how do people generally feel about improving code maintainability at the cost of negligible but known performance impacts?
View 3 Replies
Sep 30, 2011
I am writing some code that uses fixed regexs to search strings and pattern match. Its simple stuff, but I want to improve regex performance with compiling (its a high traffic website). I was thinking of compiling the regex and putting it in a Shared (static) variable inside a class. Something like this:
[Code]...
View 1 Replies
Apr 16, 2010
What is the impact of creating variables using:
Dim ds as New DataSet
ds = GetActualData()
where GetActualData() also creates a New DataSet and returns it? Does the original empty DataSet that was 'New'ed just get left in the Heap?
What if this kind of code was in many places? Would that affect the ASP.NET process and cause it to recycle sooner?
View 2 Replies
Jun 24, 2010
I have a base form and I inherit other forms from it. However, if i go back and change say the size of the base form, I don't see those changes take effect in my inherited forms. Does anyone know why that is? Is there a solution to this issue?So as far as design is goes, what exactly gets inherited by other forms?
View 9 Replies
Dec 11, 2011
Last year (2010) I came across a FANTASTIC command that allowed me to take a string of variables with a common delimiter and break it all back out into separate variables (possibly an array) with one statement.
[Code]...
As long as the delimiter was a unique specifiable character, this one-statement command could break it out into elements. my memory and point me in the right direction.
View 2 Replies
Sep 27, 2010
I have code, shown below, that works all except for 1 thing: The variables being passed byRef get passed, but once modified in the else section of the "if me.invokerequired" code of RecordData, the variables are never updated in the calling function. To reiterate, the calling function does not receive the updated data that is in the variables custid and amt.When debugging, I see the data change in the else section of "if me.invokerequired", but once it returns from the callback the data is missing.[code]
View 15 Replies
Mar 23, 2012
I define some global variables of a class as follows:
Private Class MyClass
Private var1 as Decimal
Private list1 as List(Of string)[code].....
But I found that after this form is closed, all above variables, var1, list1, list2 still exist in memory. I thought they should be collected by gc since the form is already disposed as I confirmed.
Add: I have monitored half an hour after the form is closed. But these variables are not collected by gc. I have an automatic update procedure on the form which uses above variables.Since the above variables still hold values, the automatic update procedure is always called which causes exception. (One quick fix is to check if form.isDisposed in update procedure. But I do not think this is elegeant. Besides, these variables occupy memory.)
View 2 Replies
Mar 8, 2011
Question 1: What is the difference between "Background Worker" and "Worker Pool" as indicated within the MSDN samples provided.
Question 2: I noticed while using, AddressOf _Function_, variables cannot be passed; what would be an efficient solution to this?
Question 3: While using multithreading is it required to invoke before setting variables, or only form properties?
Question 4: While using System.Net.Sockets is it safe/efficient to use Application.DoEvents while waiting for new data; or would be using a Do While loop be fine without DoEvents since the action would be multithreaded? Note: there can be up to 2000-3000 sockets in use at a time.
View 10 Replies
Jun 9, 2012
I'm new in .NET programming.I have a class Form1 that includes Button1_Click event.Button1_Click creates a multiple Text Boxies at run time)Here is the class:
Public Class Form1
Dim shiftDown As Integer
Dim counter As Integer
[code].....
View 3 Replies
Aug 22, 2009
on the custom inherited control i created, i noticed that when i bind my custom property to a data column, if that data column returns a value other than Null it always return a datarowstate of modified even if there were no changes. to produce this issue, i have below a sample code for a test inherited control
Imports System.Windows.Forms
Imports System.ComponentModel
Public Class TestControl
[code].....
View 5 Replies
Oct 14, 2011
I have two classes[code]...
How can I modify class1 in a sub in class2?
View 2 Replies
Oct 27, 2009
I am having a problem with closing a form which I have inherited I have a form called frmAddForm_Simple, which contains 4 main controls (A Data Grid, A Save Button, A Close Button and a Text Box). The idea around the form is to create a form which could be used for inputting of many different types of data which are all entered in the same way (i.e. to add a new row to a database for [Status] table or [Location] table, all of which contain 2 columns in the database (an [Id] and a [value]). On the form I have a property called _FormChanged, which when the textbox text changes, sets the property to True. I then have the following code on the Close Button:-
Public Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
If _FormChanged Then
If MessageBox.Show("Are you sure you want to close and discard any changes?", "Discard Changes",
[CODE]...
Is opened as a dialog (ShowDialog) and when I go to close the inherited form (by click on btnClose) and answer No to the above MessageBox the form closes anyway. Using the Debugged I have worked out that the following events occur in sequence (all of which runs in the Master Form mentioned above):-
1) btnClose_Click sub Routine runs
2) I answer No to the question do I want to close the form
3) The debugger steps over the Me.Close() line (as expected)
4) The debugger jumps up to the Sub Initialise (where ShowDialog was called from) and closes the form.
So at no point has the debugger even ran a line of code which reads Me.Close(), but the form closes anyway so Im fairly confused as to why the form should close.
My Master Form (frmAddForm_Simple) Code:-
Public Class frmAddForm_Simple
Private _FormChanged As Boolean = False
Private _FormLoading As Boolean = False
[CODE].............................
View 1 Replies