2.4.0-beta.81 throws an ObjectDisposedException sometimes
See original GitHub issueDescribe the bug
I needed Ctrl-C support, so I was happy to find that the latest beta had just gotten that feature. But now I’m seeing an ObjectDisposedException - but only when running without a debugger. While debugging, I see nothing.
To Reproduce I’ve produced this program that exhibits the behavior.
using System;
using System.Threading;
using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils;
using Microsoft.Extensions.Hosting;
namespace ConsoleApp1
{
class Program
{
static async Task<int> Main(string[] args)
{
return await new HostBuilder()
.RunCommandLineApplicationAsync<MyProgram>(args);
}
}
class MyProgram
{
protected int OnExecute(CommandLineApplication app, CancellationToken cancellationToken)
{
Console.WriteLine("Entered. Waiting 10s");
for (int i = 0; i < 100; i++)
{
Thread.Sleep(100);
if (cancellationToken.IsCancellationRequested)
{
Console.WriteLine("Cancelled");
break;
}
}
Console.WriteLine("Finished");
return 0;
}
}
}
Expected behavior Program terminates without exception.
Screenshots
When cancelling
When running till end
Additional context
Stacktrace thrown.
Unhandled Exception: System.ObjectDisposedException: Safe handle has been closed
at System.Threading.WaitHandle.WaitOneNative(SafeHandle waitableSafeHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
at System.Threading.WaitHandle.InternalWaitOne(SafeHandle waitableSafeHandle, Int64 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
at McMaster.Extensions.Hosting.CommandLine.Internal.CommandLineLifetime.<>c__DisplayClass11_0.<WaitForStartAsync>b__1(Object _, EventArgs __)
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
ObjectDisposedException Class (System)
An ObjectDisposedException is thrown when you try to access a member of an object that implements the IDisposable interface or IAsyncDisposable interface, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks, I ended up doing that and installed beta 99 and I no longer see the exception during shutdown.
Give 2.4.0-beta.94 a try and let me know if it doesn’t resolve your issue.
https://www.myget.org/feed/natemcmaster/package/nuget/McMaster.Extensions.CommandLineUtils/2.4.0-beta.94