1

I'm trying to store a Dictionary in the IIS Application variables using Global.ASA however I read this isnt possible due to something related to threading and dictionaries.

Since then Im trying to store an ArrayList, however this seems to fail too.

DIM LanguageArray
set LanguageArray   = CreateObject("System.Collections.ArrayList")
-- Populate Array List
Application("LanguageArray") = LanguageArray.Synchronized(LanguageArray)

I have a fairly basic setup, I declare the array list, create it and then populate it and finally try put it into the Application object. I read that Synchronized returns a thread safe wrapper and an example I saw did this however i'm pretty sure this is wrong.

I'm at a loss of what to do now, can ArrayLists even go into Application variables? If so is my call to Synchronized incorrect?

Thanks

Purplegoldfish
  • 5,268
  • 9
  • 39
  • 59
  • I'm not familiar with `Synchronized` but if it's returning a thread-safe COM object, shouldn't you be assigning it with the `Set` keyword? – Bond Aug 29 '14 at 13:58
  • @Bond I just tried SET Application("LanguageArray") = LanguageArray.Synchronized(LanguageArray) but that didnt work either. – Purplegoldfish Aug 29 '14 at 14:04
  • 1
    Have you seen [this](http://stackoverflow.com/questions/909877/using-a-dictionary-object-in-application-scope-in-classic-asp) question? One of the comments suggests it is possible to use a `Dictionary` object if done with the `` tag. Also, one of the answers shows how to use a .NET `HashTable`, again using the `` tag. – Bond Aug 29 '14 at 14:20
  • 1
    I wouldn't, better off pulling it out of a DB or file. If you do though, don't forget to use `Application.Lock`/`Unlock` when you're updating it. – Control Freak Aug 30 '14 at 02:08
  • @ZeeTee I have to do it this way to improve the performance. Not the best solution I know. And I'm only setting the collection once from Global.Asa after that it will never be updated so no need to worry about locking it. – Purplegoldfish Sep 01 '14 at 08:35
  • @Purplegoldfish You should test it against pulling the same data from a DB and see which has better performance. – Control Freak Sep 05 '14 at 18:11

1 Answers1

0

Thanks to @Bond for the link to this previous post : Using a dictionary object in application scope in Classic ASP

The solution was to use an Tag like so

<object id="YOUR_VAR_NAME" progid="Scripting.Dictionary" runat="Server"    scope="Application"></object>
Community
  • 1
  • 1
Purplegoldfish
  • 5,268
  • 9
  • 39
  • 59