Skip to content

Add Wait() method to the script host to allow blocking scripts until the app domain is torn down or ctrl+c is pressed. #685

@glennblock

Description

@glennblock

Now that we have watching we need a way to block scripts from existing whether watching is enabled or not. Using Console.ReadLine() as we do in some of our samples wont' work with -watch as the app domain is not teared down until the script finishes.

So, here is my proposal.

  • We add a ManualResetEvent under the hood with is created before the script executes. ManualResetEvent can be marshalled by ref so it can work across the app domain boundary.
  • A new Wait() method on the host will call Wait() on the underlying event.
  • When ever a change is detected and the script is going to be torn down, we set the event.
  • This will cause the script to continue executing allowing cleanup to run (like shutting down a web api) and for the script to exit.
  • The app domain will then be recycle restarting the process.

The other advantage of this approach is it will allow blocking until ctrl+c is pressed, which is more desirable for a production scenario.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions