Wrox Programmer Forums
|
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 30th, 2004, 02:51 AM
Authorized User
 
Join Date: Nov 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to destroy static variable?

The following is snippets of my code:

public class OrganizationLayerDetail : CBase
{
//an interface
private static volatile IOrganizationLayerDetail iBuilder = null;

private OrganizationLayerDetail( object AppServer, string language ) : base( AppServer, language )
{
iBuilder = CDC.PowerHRP.DALFactory.OrganizationLayerDetail.Cr eate(AppServer,Language);
}

private static void creatIbuilder( object AppServer, string language )
{
if(iBuilder == null){
    lock(typeof(IOrganizationLayerDetail))
    {
        if(iBuilder == null)
        {
        new OrganizationLayerDetail(AppServer,language);
        }
    }
}
}


public static System.Data.DataRowCollection getDetail(string strCode, object AppServer, string language )
        {
            creatIbuilder(AppServer,language );
            System.Data.DataRowCollection dst = iBuilder.getDetail(strCode,AppServer,language);
            return dst;
        }

}


I invoke "getDetail(...)" in my web form, when i first invoke it ,of course iBuilder is null , but when i closed the application, and restarted the application, iBuilder isn't null,why?

Expect for someone to help me to understand this, and give me a solution for this, thanks first!

 
Old November 30th, 2004, 10:17 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

When you run code in a web application the code is executing inside the aspnet_wp process (wp stands for 'worker process'). Because this process doesn't close after a page request, all the classes that are loaded up for a page hit stay loaded. Things aren't unloaded until you restart IIS or somehow else recycle the .net worker process. Because of this, your static variable remains alive between page hits.
 
Old November 30th, 2004, 10:26 PM
Authorized User
 
Join Date: Nov 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes ! :O), thank you very much!






Similar Threads
Thread Thread Starter Forum Replies Last Post
non-static reports to static html files miamikk ASP.NET 2.0 Basics 0 June 4th, 2007 01:48 PM
how to destroy session when window is closed chayanvinayak PHP How-To 1 June 1st, 2006 06:18 AM
destroy dataset ranakdinesh ADO.NET 3 April 21st, 2005 10:31 AM
who destroy static variables(no instance of class) MikoMax J2EE 1 March 31st, 2004 08:01 AM
Static Constructors Ibn_Aziz C# 3 December 25th, 2003 04:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.