Disposing Objects In .net?
Nov 27, 2010
What is the best practice on disposing objects in a .net method? I tend to avoid try/catch blocks as much as possible, so lets say I have a method in vb.net code behind that instantiates an object (The object may be a local variable or a class variable).Should I call objectName.dispose() when I am done with it?I am keeping in mind that I should aquire the object late and release it early during that method execution.
Private Sub Entity_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
im db As New LinqDataAccess.QuantumDataContext
Dim result = db.GetAddressType("Company")
[code]...
View 3 Replies
Similar Messages:
Mar 31, 2010
I have an UpdatePanel that contains several "items" that are in individual divs that are registered as dragdrop objects. I pass the item ID into the object. Everything appears to be working fine until I delete an item/div. The items appear in the correct divs but the ID's are mismatched as if the delete never happened. I know the dispose method is being called for each object. But I don't know how the deleted item ID is still being passed in a drag/drop object that should be re-initialized on every pageLoad. It's difficult to explain but here is some of the relevant code:
Example of generated initializations on postback:
[Code]....
View 1 Replies
Jun 11, 2010
Is it a good practice if i am disposing my on the fly created controls.
Dim d07 As DropDownList = DirectCast(LoginView2.FindControl("ActiveViewTE"), DropDownList)
d07.SelectedValue = Session("CurrAdminEngineerID")
d07.Dispose()
View 5 Replies
Jun 1, 2010
I have the Global.asax like the code below:
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
[code]...
View 3 Replies
Jul 20, 2010
I have a CustomRequestContext object that has to be disposed after each request. I create it in Page_Load and dispose of it in Page_Unload. The only issue is that in certain circumstances I need to call Server.Transfer to redirect to another aspx page instead. In this case, the object should not be unloaded until the new page is ready to be unloaded. What is the nicest way of achieving this?
View 2 Replies
Apr 13, 2010
I am writing here because I want to find out if there is a way of disposing of a custom defined membership asp.net provider within an application?If I make my custom provider disposable can I access it from the code-behind or is there an option which says the provider to be disposed?
View 5 Replies
Apr 15, 2010
it is having the grid with bulk of data. So i decided to move to Cache to strore the dataset. So that it avoids in gettin the data from DB for each time the page is loading. Suppose my idea isnot good please suggest me the best way to acheive this.My question is if i suppose store the data into the cache, how can i dispose or clear the cache from the memmory for each time i close my current page or application. I dont want the cache in memmory for long time, i want only upto the time the application is running.
View 6 Replies
Nov 17, 2010
have some Objects, lets say Employee and Role defined as below and I have defined relationships in my database that gives me a list of objects say employees and thanks to my framework each employee object also has a Role object linked via the RoleIDID, UserName, Password, Email, RoleIDRoleID, RoleNameSo in code I can do something like this
Employee emp = dataService_GetEmployeeByID(1);
string RoleName = emp.Role.RoleName;
Now here is my problemI can bind any object in a repeater and it works fine for the first level in my relationship
For instance <%# Eval("UserName") %>
But I need to be able to show the details for my child objects as well (Role) so something like this (which does not work)
<%# Eval("Role.RoleName") %>
View 2 Replies
Apr 6, 2010
I know how to bind a simple objects to a dropdown list. However I am having problems binding my objects which contains sub objects to the control.i.e. with simple object i just do ddl.DataValueField = "myproperty"
with my objects they contains sub objects which i want to bind. I have tried ddl.DataValueField = "sub-object.myproperty" which doesnt work.
View 2 Replies
Jun 21, 2010
firstly a static class only ever exists once and is not an instance. Any static members (ie static int NoOfPeople;) is stored in one place and is shared between all sessions (like the old global variables).
Now static methods is where i'm not 100% sure. If I have a static method that doesn't use any other static members could this cause inconstant results, example (this is a fairly pointless method but just a quick example of the top of my head)
[Code]....
So in this example if two sessions (or threads) were to call this at the same time - would they both get back the expected results, because the method only uses private data (a, b and totalToReturn).Im sure this sounds a little simple but I will be using static methods to build user objects and various other objects that there will have to be a 100% garentee that the objects will not get mixed up between sessions and the wrong things return to the user.
View 5 Replies
Feb 24, 2010
I'm working on a project in which we have a database, data layer (entity framework), business layer and web/UI layer.I want to use ASP.NET Dynamic Data for the web layer, but don't want it to access the data layer or database, as I want it to be purely running off business logic, and not directly accessing the data.However, it appears that Dynamic Data only allows Linq-to-SQL or entity framework data sources to be used.Has anyone used it with business-layer objects instead?
View 1 Replies
May 10, 2010
Lets say I am doing a shoping cart. I authenticate the user with a session variable.For example:
If(Request.IsAuthenticated)
// Here I want to add to the shoping cart.
// Can I do the following
Session["Cart"] = "Washing Machine";
Now will this Session["Cart"] value which is washing machine here be unique to diff customers?
View 1 Replies
Feb 1, 2010
I hosted my application in production. Within 5 to 6 hours the application pool spikes and uses more memory?
What application objects or system objects are stored in the application pool?
View 3 Replies
Apr 9, 2010
I am very new to ASP.NET, and I understand this is very nooby, but I can't figure it out myself!
I'm trying to align objects on my master page. What I mean is I have the header banner, the footer banner, and a navigation menu in the middle. Now between the navigation menu bar and the footer banner, I have a shoutbox. I want to align this shoutbox to the right side of the page, so that it is even with the edge of the navigation menu bar and footer. The width of those is 1100px. I'm using visual studio 2008.
View 18 Replies
Mar 10, 2010
Have a C# application. When I look in the project folder I see an .exe in bin/debug folder, when I click it executes the application fine. I also see the same .exe in obj/debug folder, when I click it executes but gives me error. What is the difference between these 2 objects and why do I have 2 of them?
View 4 Replies
Feb 24, 2010
Currently i am having a list like List<Tickets> allTickets.I need to select in the same list some corresponding info about the ticket writer like List<Ticket, aspnet_User>.
View 4 Replies
Oct 3, 2010
I'm preparing to pass values to a method:
private string BuildMessage(int templateID, string body, object data)
where the data param is an array of name/value pairs. To prepare my values for that data param I need to combine the properties of a strongly typed class with the values of a simple 2d array.
What's the best way to merge those values?
View 1 Replies
Nov 4, 2010
I've got this.
[Code]....
At Context.SaveChanges() nothing is being updated. I'm not receiving any erros either.
View 2 Replies
Sep 13, 2010
i want to store objects in a array, that is array of objects.
View 2 Replies
Apr 22, 2010
I have a 50 x 50 image button layout. That's 2,500 image buttons. I want to assign each imagebutton a picture depending on what is in the database. Will this be too much to do? Is there a faster way?
View 18 Replies
Jun 21, 2010
I have a list of objects (List1) and I am trying to make a copy of this list (List2) and then change one of the fields in the new list.I used :
List<MyObj> List2 = new List<MyObj>();
List2.AddRange(List1);
I alos tried:
List<MyObj> List2 = new List<MyObj>(List1);
But regardless of the method, when I do:
foreach (MyObj o in List2)
o.some_field = 2
it not only changes the field in Lis2 but alos in List1. Not sure what I am missing here.
View 3 Replies
Nov 16, 2010
I have Categoreis and Locations I would like return both in one method. How can make a use of both Categories.ToList() and Locations.ToList()? What type of object should I return?
View 1 Replies
Sep 7, 2010
In ASP.NET I have a form that has a Textbox named txtOutput and a button. In the main file.aspx.vb I can call a function from the button handler and in that function I can have
txtOutput.Text = "Some Message"
with no problem. I have a bunch of functions in several other classes. For instance I have a class named AbleCommerce that does some database functions. These functions are called from my main class. In those functions, however, I have no visibility of txtOutput. All of my classes are, unfortunately, in the default namespace which I understand is not optimal but didn't seem to impact this issue.
I know this is an easy one I've just not understood properly but it has me stumped. My gut says that I probably need to pass the Textbox object to my "other class" but can't for the life of me figure how.
View 2 Replies
Aug 30, 2010
I have this snippet in my html... Fusion Charts requires I feed it an XML to create a graph
<script type="text/javascript">
var myChart = new FusionCharts("/Content/Fusion_Charts/Charts/Column3D.swf", "myChartId", "470", "350", "0", "0");
myChart.setDataURL("/XML/Graph/?list=<%=Model.list%>");
myChart.render("Graph");
</script>
So in my XMLController I simply have a method like this
public ActionResult Graph(FusionChartsList list)
{
return View(list);
}
So my question is... how can I get the object to actually populate when passing it as url parameter??
View 1 Replies
Jan 9, 2010
what does such expression mean?
obj.DataSource = new[]
{
new {Text = "Silverlight", Count = 10, Link="/Tags/Silverlight" },
new {Text = "IIS 7", Count = 11, Link="http://iis.net" },
new {Text = "IE 8", Count = 12, Link="/Tags/IE8" },
new {Text = "C#", Count = 13, Link="/Tags/C#" },
new {Text = "Azure", Count = 13, Link="?Tag=Azure" }
};
especially these lines new {Text = "IIS 7"... how can I create such array manually to suite this DataSource
View 6 Replies