1

I have an android application as client and ASP.Net + ADO.Net hosted on GoDaddy server. The asp.net has static data structure which stores (among other) the android locations, this data structure is persist also to SQL server 2008 data base. each time the android client change position it send its location to the server which update the data structure and data base. each time the applicaton start the data structure is filled according to the persist data from the data base.

The Problems : altough the data structure is static thus should be global it looks like sometimes there are more then one instances of this static data structure.

Is anyone aware of this issue ? How can i prevent this from hapening ?

Nathan

4

1 回答 1

0

This object is has actually a dictionary with name as key and info as value. This object is updated according to android client which access the asp.net via HTTP thorugh aspx Page_Load : HttpContext.Current.Application.Lock() .

The first error is that you use that kind of lock and not the correct one.

The Application.Lock() and Application.Unlock() are designed as lock mechanism only for the Application variables.

To correct lock your static Dictionary you need to use the lock(){} as:

private static readonly object syncLock = new object();    
public static Dictionary<int, int> DictMem = new Dictionary<int, int>();

... inside some function....
lock (syncLock)
{
    // actions with your dictionary
    DictMem[2]=3;
}

Also I like to tell you that the static is not guaranty that you have only one on your program. If the provider use web garden you have more than one, and when the pool recycles then you loose them.

于 2013-03-30T19:43:16.400 回答