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

  • I think you should post some code so people here can help you – adt Mar 30 '13 at 18:24
  • Hi Nathan, welcome to StackOverflow. If you expect us to be able to help you you're going to have to produce something for us to work with, for example, code of a reduced case we can test and figure out what you did wrong. Thanks. – Benjamin Gruenbaum Mar 30 '13 at 18:24
  • on application_start i create static object and fill it with info from data base : CUtils.OnLineClientsObject = new COnLineClients();oDbUtils.BuildOnLineClientsObject() 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() .... update the data structure HttpContext.Current.Application.UnLock() – Nathan Krasney Mar 30 '13 at 19:12

1 Answers1

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.

Community
  • 1
  • 1
Aristos
  • 66,005
  • 16
  • 114
  • 150
  • Hi Aristos. Thanks , so suppose the provider use web garden - does it means that i can not use static variable ? and how can i know if he is using web garden ? – Nathan Krasney Mar 30 '13 at 19:50
  • @user1939526 No, probably is NOT user web garden. You need to use the lock as I have type it, not the Application.Lock(). – Aristos Mar 30 '13 at 19:51
  • OK. suppose i use the lock as you suggested, and suppose the provider use web garden, then this static is not global, right ? so what do i do in this case ? in need this object to be global. – Nathan Krasney Mar 30 '13 at 19:56
  • @user1939526 If you have web garden, then the static is global for each application - but if you change some value on one, is not going to see by the other. On web garden and web farm, the only solution is to use a common database. The static variables are for read only values that you like to speed up some cache schema. – Aristos Mar 30 '13 at 20:13
  • according to this link http://support.godaddy.com/groups/web-hosting/forum/topic/validation-of-viewstate-mac-failed/ GoDaddy uses Web Garden. – Nathan Krasney Mar 30 '13 at 21:35