You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using AutoMeasurement class from a non-gui library and it need to know, if the AutoMeasurement is initialized or not. (AutoMeasurement.Instance throws an exception.) Some flag like
Before calling any method of AutoMeasurement, you _always_ have to declare an instance first. i.e. AutoMeasurement.Instance = new WinFormAutoMeasurement();
I have done a log4net Appender which sends errors to GA by CSharpAnalytics. I have to check if the AutoMeasurement is initialized or not. So far, I have implemented my own flag, but it would be nice to have such flag build in the library itself, so the code would not rely on any external flags.
The problem with this is it means now every single call to AutoMeasurement has to be wrapped in the null check. The intent was you could just call it and it would do it when it is finished initializing like a queue. (although obviously there are some race conditions right now)
@damieng Yep, this log4net appender has wrap every call to the initialized check. But it is a special pieace fo code. The rest of the application does not check for initialized before AutoMeasurement.Instance use. @JimiC try/catch is IMHO to costly comparing to the null check.
Which is a hint to developer that Instance is a normal usage and InstanceOrNull is an exceptional usage. So they would not blindly wrap every call to Initialized check when it is not necessary.
Activity
[-]Add Initialized flag to AutoMeasurement[/-][+]Add a flag AutoMeasurement.Initialized[/+]JimiC commentedon Oct 22, 2015
Before calling any method of AutoMeasurement, you _always_ have to declare an instance first. i.e.
AutoMeasurement.Instance = new WinFormAutoMeasurement();@damieng This issue can be closed.
xmedeko commentedon Oct 22, 2015
I have done a log4net Appender which sends errors to GA by
CSharpAnalytics. I have to check if theAutoMeasurementis initialized or not. So far, I have implemented my own flag, but it would be nice to have such flag build in the library itself, so the code would not rely on any external flags.JimiC commentedon Oct 22, 2015
Wouldn't code like
AutoMeasurement.Instance != nullsuffice?Edit: Upon checking the above proposed code, I realized that it throws an exception.
Added 'Initialized' flag property, resolving issue AttackPattern#35.
damieng commentedon Oct 22, 2015
The problem with this is it means now every single call to AutoMeasurement has to be wrapped in the null check. The intent was you could just call it and it would do it when it is finished initializing like a queue. (although obviously there are some race conditions right now)
JimiC commentedon Oct 22, 2015
The other way around is to encapsulate the null check of the Instance in a try/catch and use a self flag as @xmedeko might do.
xmedeko commentedon Oct 22, 2015
@damieng Yep, this log4net appender has wrap every call to the initialized check. But it is a special pieace fo code. The rest of the application does not check for initialized before
AutoMeasurement.Instanceuse. @JimiC try/catch is IMHO to costly comparing to the null check.Another solution instead of
Initializedmay beWhich is a hint to developer that
Instanceis a normal usage andInstanceOrNullis an exceptional usage. So they would not blindly wrap every call toInitializedcheck when it is not necessary.