未验证 提交 6d074746 编写于 作者: S Stephen Toub 提交者: GitHub

Swap order of OnError in FileSystemWatcher.ReadDirectoryChangesCallback on Windows (#83121)

If the directory watching encounters a failure error code other than abort, the Windows implementation raises the Error event and sets EnableRaisingEvents to false. However, because it does so in that order, the Error event handler may or may not see the FSW's EnableRaisingEvents as false, based on whether there's a SynchronizingObject that results in the callback being queued.  By swapping the order to always disable first, we can ensure consistency regardless of SynchronizingObject, which also means the Error handler can choose based on the error to set EnableRaisingEvents to true again if it desires.
上级 f1e6a83b
......@@ -218,8 +218,8 @@ private void ReadDirectoryChangesCallback(uint errorCode, uint numBytes, AsyncRe
const int ERROR_OPERATION_ABORTED = 995;
if (errorCode != ERROR_OPERATION_ABORTED)
{
OnError(new ErrorEventArgs(new Win32Exception((int)errorCode)));
EnableRaisingEvents = false;
OnError(new ErrorEventArgs(new Win32Exception((int)errorCode)));
}
return;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册