I'm having about 50 Application Variables for Each Search Data Bases. Total 50 Search Db which are querid from Single Search.aspx page depending upon the QueryString passed in URL it connects to Specific DB.

Eg: if Search.aspx?li=1 then Connect to 1SearchDB

if Searcg.aspx?li=2 then Connect to 2SearchDB.....

50SearchDB I am Maintaining the Total Visitors to each SearchDB depending upon the QueryString in URL and increment the Application Variable that are in GLOBAL.ASAX file.

In Global.asax:

void Application_Start(object sender, EventArgs e)  
    { 
        // Code that runs on application startup 
        Application["1"] = 0;           
        Application["2"] = 0; 
        . 
        . 
        Application["50"] = 0; 

    } 

In Page Load of Search.aspx.cs:

int LocalBody = Convert.ToInt32(Request.QueryString["li"]); 
public void Page_Load(object sender, EventArgs e) 
    { 
    Label1.Text = GetHits(LocalBody).ToString(); 
    } 


     private int GetHits(int LocalBody) 
        { 
            int counter=0; 
            switch (LocalBody) 
            { 
                case 1: 
                    Application["1"] = (int)Application["1"] + 1; 
                    counter=(int)Application["1"]; 
                    break; 
                case 2: 
                     Application["2"] = (int)Application["2"] + 1; 
                    counter=(int)Application["2"]; 
                    break; 
                . 
                . 
                case 50: 
                    Application["50"] = (int)Application["50"] + 1; 
                    counter=(int)Application["50"]; 
                    break;            default: 
                    break; 
            } 
            return counter; 

        } 

Now, i want to Add these Application Variable to QUEUE and on Reaching 1000 or after Some Specified TIME INTERVAL say 20 Minutes it must Write the values to DB or Windows Event Log.

Whether to Write any Service or else...!

有帮助吗?

解决方案

The Application object will remain in memory for as long as the WebApp is in memory. IIS can shut down the WebApp if there is no request for some amount of time. In that case the values stored in the Application object would be lost. Assuming even if IIS doesnt shut down the web app, the object resides in the memory of the site. No external service can access this object till you persist it to some shared location (say a database or a message queue).

My suggestion would be not use the application object. Instead persist it to an inmemory store. I am assuming the reason you dont want to persist to the database every time the value updates is so as to avoid writing to disk. Hence am suggesting using a message queue like MSMQ or DotNetMQ or a key value store like Redis.

Once you have your data persisted in a shared location, you can have a service poll the location and save every 1000 items or every 20 mins.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top