I need some global class instances for a project. A Dictionary and a Random or whatever.
It seems to me that I could create them in an App Constructor method or in the App Open Event.
Is there a reason to prefer one over the other?
I need some global class instances for a project. A Dictionary and a Random or whatever.
It seems to me that I could create them in an App Constructor method or in the App Open Event.
Is there a reason to prefer one over the other?
The application’s constructor fires extremely early and you have to be careful that all of the code it calls can handle that. For example, code can’t access the application object via App because it isn’t finished being created.
I would use the Open event.
Use a Computed Property and implement only the Get portion, something like this:
Computed Property GlobalDictionary As Dictionary
Get
static d as new Dictionary
return d
The Dictionary will be created only when needed, and you can never set it to Nil, even accidentally.