GithubHelp home page GithubHelp logo

Comments (5)

alexrp avatar alexrp commented on July 20, 2024

I'm not actually sure where/when we could safely do this. Even AppDomain.CurrentDomain.ProcessExit isn't really safe since there might be other handlers that expect to be able to use System.Terminal.

from cathode.

Thraka avatar Thraka commented on July 20, 2024

Is it possible to add a method that can be called that resets it? This way I can call it as I know I terminate.

from cathode.

alexrp avatar alexrp commented on July 20, 2024

That sounds reasonable.

from cathode.

alexrp avatar alexrp commented on July 20, 2024

@Thraka For your use case, would it be acceptable if the cleanup method would perform terminal state cleanup and also exit the process immediately after? This would greatly simplify matters in the library since I would not need to care about users calling the cleanup method and then trying to use the library after.

It might look something like this:

static class Program
{
    static void Main(string[] args)
    {
        using (var lifetime = TerminalLifetime.Create())
        {
            // ... work ...

            if (workFailed)
                lifetime.ExitCode = 1; // defaults to zero
        }

        // lifetime.Dispose() called here, cleans up terminal state and exits
    }
}

To simplify this, I'd probably also provide a package that works similarly to DragonFruit, i.e. it generates the real Main for your application, takes care of the TerminalLifetime for you, and calls your entry point method.


PS: I know it's been a while since this issue was opened... I'm only now getting around to continuing the project with .NET 6 being out.

from cathode.

alexrp avatar alexrp commented on July 20, 2024

Resolved in 443eff9.

For your use case, would it be acceptable if the cleanup method would perform terminal state cleanup and also exit the process immediately after? This would greatly simplify matters in the library since I would not need to care about users calling the cleanup method and then trying to use the library after.

I'll spin this off into a separate issue.

from cathode.

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.