Coder Social home page Coder Social logo

Comments (6)

JimiC avatar JimiC commented on July 19, 2024

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.

xmedeko avatar xmedeko commented on July 19, 2024

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.

JimiC avatar JimiC commented on July 19, 2024

Wouldn't code like AutoMeasurement.Instance != null suffice?

Edit: Upon checking the above proposed code, I realized that it throws an exception.

from csharpanalytics.

damieng avatar damieng commented on July 19, 2024

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.

JimiC avatar JimiC commented on July 19, 2024

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.

xmedeko avatar xmedeko commented on July 19, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.