我正在尝试编写一个自定义 msbuild 任务来检查网站是否可用。但是当我的任务结束时,它会抛出带有以下堆栈跟踪的 ObjectDisposedException。
at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)
at System.StubHelpers.StubHelpers.SafeHandleAddRef(SafeHandle pHandle, Boolean& success)
at Microsoft.Win32.Win32Native.SetEvent(SafeWaitHandle handle)
at System.Threading.EventWaitHandle.Set()
at Microsoft.Build.Utilities.ToolTask.ReceiveStandardErrorOrOutputData(DataReceivedEventArgs e, Queue dataQueue, ManualResetEvent dataAvailableSignal)
at Microsoft.Build.Utilities.ToolTask.ReceiveStandardOutputData(Object sender, DataReceivedEventArgs e)
at System.Diagnostics.Process.OutputReadNotifyUser(String data)
at System.Diagnostics.AsyncStreamReader.FlushMessageQueue()
at System.Diagnostics.AsyncStreamReader.GetLinesFromStringBuilder()
at System.Diagnostics.AsyncStreamReader.ReadBuffer(IAsyncResult ar)
at System.Runtime.Remoting.Messaging.AsyncResult.SyncProcessMessage(IMessage msg)
at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)
at System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.DoAsyncCall()
at System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack(Object o)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
我不明白是什么导致了这种行为。
这是显示问题的最简单的代码片段。
public class CustomTask : Task {
public override bool Execute() {
Thread.Sleep(10000);
return true;
}
}