C# - What Is The Life Span Of A Field In A Static Class

Feb 2, 2011

I have a simple web service, in it i have a static class which has a static collection to remember alive tokens.

I just want to make sure that the token collection lives until the next iisreset or the application pool recycles.

And what is the difference between remembering states in Application bag and static class?

View 1 Replies


Similar Messages:

C# - How To Lock A Private Static Field Of A Class In One Static Method

Mar 26, 2011

I have a private static field in my Controller class in an MVC web application.

I have a static method in that controller that assigns some value to that static field, I want to apply lock on that static field until some other instance method in the controller uses the value stored in the static field and then releases it.

DETAILS:

I have a controller named BaseController having a static ClientId field as follows and two methods as follows:-

public static string ClientId = "";
static void OnClientConnected(string clientId, ref Dictionary<string, object> list)
{
list.Add("a", "b");
// I want the ClientId to be locked here, so that it can not be accessed by other requests coming to the server and wait for ClientId to be released:-
BaseController.clientId = clientId;
}
public ActionResult Handler()
{
if (something)
{
// use the static ClientId here
}
// Release the ClientId here, so it can now be used by other web requests coming to the server.
return View();
}

View 1 Replies

What Is Life Span For Items Stored In View State

Sep 30, 2010

asp.net - what is life span for items stored in view state?

View 2 Replies

Public Static Variable Declared In Public Static Class MyGlobals In A 'Code File' Template?

Jan 27, 2011

I have a question about C Sharp ASP.NET:Is there a difference (in code speed, resources) between:public static variable declared in public static class MyGlobals in a 'Code File' template;and the variable declared in a normal 'Class File' template;I use this variable in 2 different Class Files and also in _Default Page codebehind cs file.In fact in my case I need about 20 global variables of type List<string>.

View 9 Replies

Web Forms :: Get All HTML SPAN Tags Having Particular Class Name Using Regular Expressions

Aug 10, 2012

Code to read the span having the particular class name and assign to match collection.

I am having a set of html tags.

<span><a href="asb.aspx">Dummy</a></span>

<span class="active"><a href="abc.aspx">Hi thi is titile</a></span>

I need to get the span having the class name ="active".That is i need the result

<span class="active"><a href="abc.aspx">Hi thi is titile</a></span>

It will be fine if i get the text in the a tag that is with in the span having the class name "active".

View 1 Replies

Configuration :: Field Initializer Cannot Reference The Non-static Field?

Feb 3, 2011

when i am declaring my connection string i am getting error below is my connection string

[Code]....

the error is A field initializer cannot reference the non-static field, method, or property 'Default3.con1' .i am unable to type con1.

View 2 Replies

Static Class In App_Code?

Jan 8, 2010

If a static class is put in App_Code, does that imply only one instance will be created, shared by different http requests?Or each request still brings one request?

View 3 Replies

Use A Static DbUtil Class For Web Is It Dangerous?

Oct 4, 2010

is it ok to use something like this in the web:
(my application is on asp.net mvc)

public static class DbUtil
{
public static int Insert(object o, string cs)
{
using (var conn = new SqlConnection(cs))
using (var cmd = conn.CreateCommand())
{
conn.Open();
return Convert.ToInt32(cmd.ExecuteScalar());

[Code]....

View 2 Replies

MVC :: Accessing An Existing Static Class?

Mar 15, 2011

So i have some existing functionality from an older ASP.Net app that is a static class.

Say there's a static method in that class that returns a dataset that I would like to bind to something like a gridview or whatever I can build using MVC3.

View 2 Replies

C# - Access Static Class From Form?

May 10, 2010

I am using <%# MyFormatClass(Eval("fieldname")) %> to display data in a grid view on my page. MyFormatClass works fine, but now I want to move it to a central location that can be used by many pages. When I try to access the class <%# Utils.MyFormatClass(Eval("fieldname")) %> it no longer works. Is this something we are allowed to do?

View 1 Replies

C# Thread Safe Static Read Only Field?

Mar 2, 2010

I have the following code in my ASP.NET project

public sealed class IoC
{
private static readonly IDependencyResolver resolver =
Service.Get("IDependencyResolver") as IDependencyResolver;
static IoC()
{
}
private IoC()

[Code]....

View 2 Replies

Static Field Initializer Runs Before Application_start, Sometimes?

Oct 29, 2010

I've got an ASP.NET web app that is starting to show some very strange behavior. Here's some example code:

// in Bar.cs
public class Bar {
public static Baz baz = Something.Step2();
}
// in Global.asax
public void Application_Start(...) {
Something.Step1();
}

The short version of the story is this: On some machines, Something.Step2 is executed before Something.Step1 and is throwing an unhandleable exception. On other machines, Step1 correctly executes before Step2. Global.asax and all the objects it uses do not refer to Bar at all.

When are static fields supposed to execute in relation to other programming elements? Why would two machines (both Win7 64-bit, both with .NET 4.0, same IIS version, etc) execute things in different orders? The order is consistent on each machine too. On my machine, it always executes Step2 before Step1, but on my coworker's machine it always executes Step1 before Step2.Update I've found the root cause why my static field is being accessed. Class "Bar" from my example is actually a custom authentication module, and is referenced in web.config as the Authentication handler under System.webServer. If I remove that line from web.config, my system calls Step1 first and never calls Step2 at all. My question changes subtly to: "Why does web.config cause my static initializers to fire, and why does it cause them to fire before Application_Start executes?"

View 1 Replies

Database - Storing Connection In A Static Class?

Mar 4, 2010

Since I'm using Postgresql and can't use LINQ to SQL, I wrote my own wrapper classes.

This is a part of the Student class:

[code]....

It works now! I replaces all Run methods in the Student class with DB.Run

But I want to know if it will work fine with a lot of people online, not me only. I'm not sure how static things work with ASP.NET, maybe it'll eat a lot of memory?..

View 3 Replies

Way To Generate Links Automatically Via A Static Class

Jun 10, 2010

I would like to generate my links automatically via a static class in each of my aspx pages (or in a common BasePage).Currently I use this:

private const string TEMPLATE =
"~/One.aspx";
public static string Link ()
(
string link = String.Format(TEMPLATE);
return link;
)

But the name of my page, One.aspx is hardcoded. Is it possible to generate the path instead of this hardcoded constant TEMPLATE. You should know that I do not instantiate the class before creating the link.

View 1 Replies

C# - How To Create A Static Array Containing Custom Class

Jan 6, 2010

I have a method that returns an array of custom class objects that are created by parsing a text file. At the moment every time I use it I am rereading the file which isn't very efficient.

What I wat to do is create an array containing the objects when the page loads and store them in an array which can then be used later.

[Code]....

I thought I could create the static object using something like:

static Album myAlbums[] = readArray("Albums.txt");

but I am getting the following error:

A field initializer cannot reference the nonstatic field, method, or property 'B2M._Default.readArray(string)'

I am new to C# so this is probably something dumb. (Feel free to poke fun in my general direction if this is the case!)

View 2 Replies

C# - How To Access Singleton Class's Static Method

Nov 17, 2010

I have some confusion with singleton class, below are my some points:

1.Can singleton class have static method?,if yes then how we call that methods?
2.what is main difference between Static class and Singleton Class?

I have created my singleton class as follows:

[Code]....

In Above class structure I have created two method one is Static and second is non static, When I am trying to access Static Method it gives me compile time error.

How can I use static method of singleton class?

View 7 Replies

Architecture :: Advantage Of Singleton Class Over Static?

Mar 30, 2010

See in below I have writtine a

1. Singleton class Emp1 with Display Method and
2. Static Class with Static Method Display.

What is the advantage of singleton class over Static Class with Static members?

[Code]....

View 9 Replies

C# - Deallocating Memory, Static Class Destructor?

Jan 13, 2011

I have a static class I'm using as my data layer in my website. In this class, I have string arrays that store queried information that I can access later. Here's the part of my class and the method in question:

public static class data_layer
{
ivate static string[] items;
private static string[] description;
//will return description for an item id. if no item id is found, null is returned
public static string getDesc(string key)
[code]....

View 2 Replies

C# - To Use Static Functions If No Class Members Are Needed?

Jan 21, 2011

I have a member function that does not depend on any member variables of the class. (in my case the class is an ASP.Net Page)

The function is protected, I dont need it outside of this class. Its only purpose is to build an URL from an given object.

Should I make all my functions static if they dont depend on the class, even if they are not used outside of this class?

View 6 Replies

C# - Get The Name Of The Class Without Instantiating Object Or Having A Static Method?

Feb 22, 2011

I hate to see the name of the class used as a string parameter like "FileDownloader" in the code, and I would like to use something like this FileDownloader.Name(), where FileDownloader is name of the class.
Only problem is that I can't find out how to do that without instantiating object or creating a static method...

Is there a way to get a class name in .net without having the object instance and without creating a static method that returns the name of the class?

View 3 Replies

C# - Accessing Inherited Properties Through A Static Class?

Nov 12, 2010

Currently, I am accessing the property by creating a static method like the one below.

public static class CartCollection : List<Cart>
{
public static void Add(Cart Cart)

[code]...

View 3 Replies

Web Forms :: Basics About Declaring Static Class

May 7, 2015

What is the use of declaring the static class. I know that we cant create the object for the static class but i want to know that is the use of creating the class as static.

View 1 Replies

Static Variable Inside A Class In Web Application

Jul 28, 2011

I understand the problem of the static variable inside a class in the web application, now I try to create a simple class to deal with SQL Server for example, so I created Static Method inside this class, this static method used in insert, update and delete from database, I wonder if this is safe, and there is no problems will appear ?

View 10 Replies

Access Static Class Properties From Aspx Page?

Jan 28, 2010

I am on .aspx page and i want to take the width and height of a control from a static class
where i have defined them as constans.

Is there any way to access that class directly from the aspx page?

I know that i can make a method like:

width="<%= getWidthSize() %>"

and inside the aspx.cs to define this method to take the size from that static class.

But i am asking if this could be directly managed from the web aspx page...?

View 2 Replies

Intellisense/Reference To Static Class Object Lost

Jul 21, 2010

We have a Static class that 's called CData in our asp.net c# app.It handles all the data layer CRUD functionality on our pages.

Problem is, were are losing the intellisense reference in our pages to it.For example: we would expect to type CData.(dot) and have a list of methods and properties available to us.

Nope. Not there.

I kind of thought it was because the file was getting too long at 3000 lines of code, since some other static classes were working ok.

So then I thought that I'd try wrapping the CData Class in a namespace. That worked, but of course I had to put an include statement of the top of each page that's using CDATA, also, now some of the other developers are getting errors in there pages complaining about missing methods that are in CDATA, but their pages are not seeing.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved