Comments (6)
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.
from csharpanalytics.
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.
from csharpanalytics.
Wouldn't code like AutoMeasurement.Instance != null
suffice?
Edit: Upon checking the above proposed code, I realized that it throws an exception.
from csharpanalytics.
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)
from csharpanalytics.
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.
from csharpanalytics.
@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.
Another solution instead of Initialized
may be
public static BaseAutoMeasurement InstanceOrNull { get { return _instance; } }
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.
from csharpanalytics.
Related Issues (20)
- GetEntryAssembly vs GetExecutingAssembly HOT 2
- ASP.NET support HOT 13
- Build break because of requestUri.ShouldUsePostForRequest() HOT 1
- Exception HOT 6
- Assembly.GetEntryAssembly can be null and causes crashes. HOT 3
- Windows Phone 8.1 Support HOT 1
- Prior requests cause null exception in BaseAutoMeasurement::Request HOT 1
- Exception on Start() HOT 8
- Starting multiple instances of a WPF application at same time throws Exception in Start()
- Make internal classes public HOT 1
- TrackEvent exchange parameters action and category HOT 1
- Allow to use GA debug URL
- MeasurementAnalyticsClient.AdjustUriBeforeRequest cuts strings with special chars HOT 2
- Setting SetOptOut before Start causes crash
- Support WPF .NET 4.0 Client Profile applications HOT 5
- At one of my testing machines I get an deserializing error
- Session start and session end time stamps registered at GA are very often too late relative to other events HOT 3
- proxy support HOT 1
- Unhandled Exception HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from csharpanalytics.