0

I'm programming a Chat. Basically, I have a window (TextBox) where I want to display all users that are in the conversation at the moment but I do not wish to use a database.

So, I would need to keep my table of active users somewhere persistent something that does not get erased on refresh.

I looked in to Sessions. However, they expire and I can't keep the array of my active users in there. I also looked in Application Object and it seems this could solve my dilemma. However:

Say I call

String[] users = new users String[1000];  
Application['users'] = users;  

In my Page_Load() method, sure I can store the new user in to that table but then each page load will override the table and I will always show only one user but I guess implementing something along lines is isset() could solve that.

Picrofo Software
  • 5,475
  • 3
  • 23
  • 37
Sterling Duchess
  • 1,970
  • 16
  • 51
  • 91

1 Answers1

2

So I would need to keep my table of active users somewhere persistant something that does not get erased on refresh.

A database is the solution for that.

The Application[] is actually a static variable, so its delete it when pool recycle, and also if you have more than one pool, than you have more than one common Application variables.

Read about application state: Using static variables instead of Application state in ASP.NET

See some other examples with asp.net chat:

http://www.codeproject.com/Articles/33817/Build-a-Web-based-Chat-using-ASP-NET-Ajax

Community
  • 1
  • 1
Aristos
  • 66,005
  • 16
  • 114
  • 150
  • How about Application('users', array()); I'm guessing it's the same thing. Tho i was told i should be able to implement this via Application() – Sterling Duchess Nov 04 '12 at 18:04
  • @kellax Application variables are a simple static variable. You can not keep it there and have it as you like, on recycle of the pool you going to lose them, Make a test and you see it. – Aristos Nov 04 '12 at 18:20
  • Since I'm very i googled " Pool Recycle " but couldnt find what that is. Page reload/refresh or ? – Sterling Duchess Nov 04 '12 at 18:26
  • @kellax Totally lost you. You look for a place to share/save some data, if you place them there on application, then they going to be erase if the pool recycle. Google "application pool recycle asp.net" – Aristos Nov 04 '12 at 18:27
  • By default it recycles ever 29 hours? If so than this should be very good for me. Thanks for the input tho helped a lot. – Sterling Duchess Nov 04 '12 at 18:35
  • @kellax You can make it also to never recycle if you have access to the iis. But you must have only one pool for your application, this is also default, so probably you have one pool. The pool recycle depend form how you have setup it. You can setup it to recycle every some hours, you can setup to recycle it if the memory is more than something, etc... – Aristos Nov 04 '12 at 18:36