2

I'm writing a simple chat web service with C# ASP.Net, which I am new to.

Server maintains a List<ConnectedUser>, where the ConnectedUser object is a class holding ID, username, and a list of waiting messages.

I want all connected clients to be able to access the list on the server.

I tried Application state, but I found it will not hold custom classes, even when I let it be serializable. I tried a static class holding the global variables. Neither persist changes between calls to the service.

How should I be doing this? Thank you.

Daniel
  • 169
  • 5
  • Wouldn't that be very runtime intensive, making SQL calls? Is it the most efficient way, or is there a best DBMS for this? – Daniel Jan 01 '12 at 17:25
  • 2
    Not all databases are disk-backed. Not all databases use SQL. I suggest you use an in-memory table if you need fast performance. – user703016 Jan 01 '12 at 17:33

2 Answers2

1

For storing custom class in Application State you don't need to Serialize/Deserialize and normally they can be accessible.

Here is some threads talking about this:

Community
  • 1
  • 1
Qorbani
  • 5,286
  • 2
  • 33
  • 45
  • Will only work with a single worker process, on a single machine, so long as there are no worker process crashes. So not suitable for production use, etc – Kieren Johnstone Jan 01 '12 at 22:49
0

A couple of options (we use both):

1) Store the values to be accessible in a static class that is initialized in global.asax or on the first user request.

2) Store the values in HttpRunTime.Cache, especially if it needs to be refreshed periodically (you can refresh in the timeout event).

competent_tech
  • 42,617
  • 10
  • 80
  • 106