Почему Winforms UI Thread продолжает, казалось бы, не связанную работу после невозможности получить блокировку записи с помощью ReaderWriterLockSlim? - PullRequest
0 голосов
/ 06 марта 2019

В приведенной ниже трассировке стека есть некоторый код рисования Winforms, который в конечном итоге получает блокировку записи с использованием ReaderWriterLockSlim (настраивается с помощью LockRecursionPolicy.SupportsRecursion). Блокировка недоступна, поэтому она блокируется в WaitHandle.InternalWaitOne. Но затем этот же поток продолжается в NativeWindow.Callback, который, в свою очередь, запускает еще какой-то код рисования, который хочет использовать тот же ReaderWriterLockSlim для получения блокировки чтения. Поскольку есть ожидающий писатель, больше читателей не позволено, и таким образом поток блокируется.

Но как это возможно, что после того, как он застрял в WaitHandle.InternalWaitOne в первый раз, поток по-прежнему получает, казалось бы, не связанную работу (NativeWindow.Callback) и продолжает эту работу? Поскольку это синхронная блокировка (аффинная блокировка потока, а не асинхронная блокировка), она должна блокировать поток прямо там, при этом желая взять блокировку записи, нет?

Not Flagged >   6628    0   Worker Thread   UI-thread   win32u.dll!7573249c
                    ntdll.dll!77acf29c()
                    [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
                    KERNELBASE.dll!749924c0()
                    win32u.dll!7573249c()
                    user32.dll!77906b37()
                    user32.dll!77906acd()
                    combase.dll!76fcb334()
                    combase.dll!76f8babe()
                    [Managed to Native Transition]
                    mscorlib.dll!System.Threading.WaitHandle.InternalWaitOne(System.Runtime.InteropServices.SafeHandle waitableSafeHandle, long millisecondsTimeout, bool hasThreadAffinity, bool exitContext)
                    mscorlib.dll!System.Threading.WaitHandle.WaitOne(int millisecondsTimeout, bool exitContext)
                    mscorlib.dll!System.Threading.WaitHandle.WaitOne(int millisecondsTimeout)
                    System.Core.dll!System.Threading.ReaderWriterLockSlim.WaitOnEvent(System.Threading.EventWaitHandle waitEvent, ref uint numWaiters, System.Threading.ReaderWriterLockSlim.TimeoutTracker timeout, System.Threading.ReaderWriterLockSlim.EnterLockType enterLockType)
                    System.Core.dll!System.Threading.ReaderWriterLockSlim.TryEnterReadLockCore(System.Threading.ReaderWriterLockSlim.TimeoutTracker timeout)
                    System.Core.dll!System.Threading.ReaderWriterLockSlim.TryEnterReadLock(System.Threading.ReaderWriterLockSlim.TimeoutTracker timeout)
                    DAL.dll!DAL.PersistenceProviderBase.Read<System.__Canon>(System.Func<System.__Canon> work)
                    DAL.dll!DAL.PersistenceProviderBase.GetData(System.Type type)
                    DAL.dll!DAL.PersistenceProviderBase.GetSingleItemGeneric(System.Type type, System.Func<Model.PersistableEntity> createIfNotExists, bool linkUnit, bool linkProject)
                    Business.dll!Business.Settings.SettingsController.GetSettingsEntityGeneric(System.Type settingsType)
                    Business.dll!Business.Settings.SettingsController.GetSettingsEntity<Model.Entities.Settings.UnitWideSettings.WizardSettings>()
                    him.exe!View.Tabs.WorkflowViews.WorkflowView.GetControlsOrdered.AnonymousMethod__128_0(View.WorkflowManagerUI.WorkflowComponentControl c)
                    System.Core.dll!System.Linq.Enumerable.WhereEnumerableIterator<View.WorkflowManagerUI.WorkflowComponentControl>.MoveNext()
                    System.Core.dll!System.Linq.Buffer<View.WorkflowManagerUI.WorkflowComponentControl>.Buffer(System.Collections.Generic.IEnumerable<View.WorkflowManagerUI.WorkflowComponentControl> source)
                    System.Core.dll!System.Linq.OrderedEnumerable<View.WorkflowManagerUI.WorkflowComponentControl>.GetEnumerator()
                    him.exe!View.Tabs.WorkflowViews.WorkflowView.xscPaintArea_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
                    System.Windows.Forms.dll!System.Windows.Forms.Control.RaisePaintEvent(object key, System.Windows.Forms.PaintEventArgs e)
                    DevExpress.Utils.v17.2.dll!DevExpress.XtraEditors.XtraScrollableControl.OnPaint(System.Windows.Forms.PaintEventArgs e)
                    System.Windows.Forms.dll!System.Windows.Forms.Control.PaintTransparentBackground(System.Windows.Forms.PaintEventArgs e, System.Drawing.Rectangle rectangle, System.Drawing.Region transparentRegion)
                    System.Windows.Forms.dll!System.Windows.Forms.Control.PaintBackground(System.Windows.Forms.PaintEventArgs e, System.Drawing.Rectangle rectangle, System.Drawing.Color backColor, System.Drawing.Point scrollOffset)
                    System.Windows.Forms.dll!System.Windows.Forms.Control.PaintBackground(System.Windows.Forms.PaintEventArgs e, System.Drawing.Rectangle rectangle)
                    System.Windows.Forms.dll!System.Windows.Forms.Control.OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
                    DevExpress.XtraEditors.v17.2.dll!DevExpress.XtraEditors.BaseButton.OnPaintBackground(System.Windows.Forms.PaintEventArgs e)
                    System.Windows.Forms.dll!System.Windows.Forms.Control.PaintWithErrorHandling(System.Windows.Forms.PaintEventArgs e, short layer)
                    System.Windows.Forms.dll!System.Windows.Forms.Control.WmPaint(ref System.Windows.Forms.Message m)
                    System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)
                    DevExpress.Utils.v17.2.dll!DevExpress.Utils.Controls.ControlBase.WndProc(ref System.Windows.Forms.Message m)
                    DevExpress.XtraEditors.v17.2.dll!DevExpress.XtraEditors.BaseControl.WndProc(ref System.Windows.Forms.Message msg)
                    System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m)
                    System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)
                    System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam)
                    [Native to Managed Transition]
                    user32.dll!7791d313()
                    user32.dll!778fe8da()
                    user32.dll!778fe510()
                    user32.dll!77908b69()
                    ntdll.dll!77ad0fd6()
                    win32u.dll!757327ec()
                    user32.dll!778fe340()
                    user32.dll!778fdfe0()
                    combase.dll!76fcbe1c()
                    combase.dll!76fcc0ac()
                    combase.dll!76fcb334()
                    combase.dll!76f8babe()
                    mscorlib.ni.dll!6a726b31()
                    [Managed to Native Transition]
                    mscorlib.dll!System.Threading.WaitHandle.InternalWaitOne(System.Runtime.InteropServices.SafeHandle waitableSafeHandle, long millisecondsTimeout, bool hasThreadAffinity, bool exitContext)
                    mscorlib.dll!System.Threading.WaitHandle.WaitOne(int millisecondsTimeout, bool exitContext)
                    mscorlib.dll!System.Threading.WaitHandle.WaitOne(int millisecondsTimeout)
                    System.Core.dll!System.Threading.ReaderWriterLockSlim.WaitOnEvent(System.Threading.EventWaitHandle waitEvent, ref uint numWaiters, System.Threading.ReaderWriterLockSlim.TimeoutTracker timeout, System.Threading.ReaderWriterLockSlim.EnterLockType enterLockType)
                    System.Core.dll!System.Threading.ReaderWriterLockSlim.TryEnterWriteLockCore(System.Threading.ReaderWriterLockSlim.TimeoutTracker timeout)
                    System.Core.dll!System.Threading.ReaderWriterLockSlim.TryEnterWriteLock(System.Threading.ReaderWriterLockSlim.TimeoutTracker timeout)
                    DAL.dll!DAL.PersistenceProviderBase.Modify<System.__Canon>(System.Func<System.__Canon> work, bool save)
                    DAL.dll!DAL.PersistenceProviderBase.ModifyNoSave<System.Collections.Generic.IEnumerable<Model.Entities.Communication.CommunicationActuatorProperties.CommunicationActuatorProperties>>(System.Func<System.Collections.Generic.IEnumerable<Model.Entities.Communication.CommunicationActuatorProperties.CommunicationActuatorProperties>> work)
                    DAL.dll!DAL.PersistenceProviderBase.AddDataNoSave<Model.Entities.Communication.CommunicationActuatorProperties.CommunicationActuatorProperties>(Model.Entities.Communication.CommunicationActuatorProperties.CommunicationActuatorProperties entity, bool linkUnit, bool linkProject)
                    Business.dll!Business.Communication.CommunicationModuleProcessor<Model.Entities.Communication.ProjectorCommunicationModule, Model.Entities.Communication.CommunicationActuatorProperties.ProjectorCommunicationActuatorProperties, Model.Entities.Communication.CommunicationTriggerProperties.NoCommunicationTriggerProperties>.SwapModuleForActuator(Model.Entities.Communication.CommunicationModule module, Model.Entities.WorkflowManager.Components.Actuators.CommunicationActuator actuator)
                    him.exe!View.WorkflowManagerUI.Actuators.CommunicationActuatorPropertyForm..ctor.AnonymousMethod__0(object sender, System.EventArgs args)
                    [Native to Managed Transition]
                    [Managed to Native Transition]
                    DevExpress.XtraEditors.v17.2.dll!DevExpress.XtraEditors.Repository.RepositoryItem.RaiseEditValueChangedCore(System.EventArgs e)
                    DevExpress.XtraEditors.v17.2.dll!DevExpress.XtraEditors.Repository.RepositoryItem.RaiseEditValueChanged(System.EventArgs e)
                    DevExpress.XtraEditors.v17.2.dll!DevExpress.XtraEditors.BaseEdit.RaiseEditValueChanged()
                    DevExpress.XtraEditors.v17.2.dll!DevExpress.XtraEditors.BaseEdit.OnEditValueChanged()
                    DevExpress.XtraEditors.v17.2.dll!DevExpress.XtraEditors.TextEdit.OnEditValueChanged()
                    DevExpress.XtraEditors.v17.2.dll!DevExpress.XtraEditors.PopupBaseAutoSearchEdit.OnEditValueChanged()
                    DevExpress.XtraEditors.v17.2.dll!DevExpress.XtraEditors.BaseEdit.OnEditValueChanging(DevExpress.XtraEditors.Controls.ChangingEventArgs e)
                    DevExpress.XtraEditors.v17.2.dll!DevExpress.XtraEditors.TextEdit.OnEditValueChanging(DevExpress.XtraEditors.Controls.ChangingEventArgs e)
                    DevExpress.XtraEditors.v17.2.dll!DevExpress.XtraEditors.BaseEdit.EditValue.set(object value)
                    DevExpress.XtraEditors.v17.2.dll!DevExpress.XtraEditors.PopupBaseEdit.AcceptPopupValue(object val)
                    DevExpress.XtraGrid.v17.2.dll!DevExpress.XtraEditors.GridLookUpEdit.AcceptPopupValue(object val)
                    DevExpress.XtraEditors.v17.2.dll!DevExpress.XtraEditors.PopupBaseEdit.UpdateEditValueOnClose(DevExpress.XtraEditors.PopupCloseMode closeMode, bool acceptValue, object newValue, object oldValue)
                    DevExpress.XtraEditors.v17.2.dll!DevExpress.XtraEditors.PopupBaseEdit.DoClosePopup(DevExpress.XtraEditors.PopupCloseMode closeMode)
                    DevExpress.XtraEditors.v17.2.dll!DevExpress.XtraEditors.PopupBaseEdit.ClosePopup(DevExpress.XtraEditors.PopupCloseMode closeMode)
                    DevExpress.XtraEditors.v17.2.dll!DevExpress.XtraEditors.PopupBaseEdit.ClosePopup()
                    DevExpress.XtraGrid.v17.2.dll!DevExpress.XtraEditors.Repository.RepositoryItemGridLookUpEditBase.DoClosePopup()
                    DevExpress.XtraGrid.v17.2.dll!DevExpress.XtraGrid.Views.Grid.Handler.GridRegularRowNavigator.OnMouseUp(DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hitInfo, DevExpress.Utils.DXMouseEventArgs e)
                    DevExpress.XtraGrid.v17.2.dll!DevExpress.XtraGrid.Views.Grid.Handler.GridHandler.OnMouseUp(System.Windows.Forms.MouseEventArgs ev)
                    DevExpress.Utils.v17.2.dll!DevExpress.Utils.Controls.BaseHandler.ProcessEvent(DevExpress.Utils.Controls.EventType etype, object args)
                    DevExpress.XtraGrid.v17.2.dll!DevExpress.XtraGrid.Views.Base.Handler.BaseViewHandler.ProcessEvent(DevExpress.Utils.Controls.EventType etype, object args)
                    DevExpress.XtraGrid.v17.2.dll!DevExpress.XtraGrid.GridControl.OnMouseUp(System.Windows.Forms.MouseEventArgs ev)
                    System.Windows.Forms.dll!System.Windows.Forms.Control.WmMouseUp(ref System.Windows.Forms.Message m, System.Windows.Forms.MouseButtons button, int clicks)
                    System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)
                    DevExpress.XtraEditors.v17.2.dll!DevExpress.XtraEditors.Container.EditorContainer.WndProc(ref System.Windows.Forms.Message m)
                    DevExpress.XtraGrid.v17.2.dll!DevExpress.XtraGrid.GridControl.WndProc(ref System.Windows.Forms.Message m)
                    System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m)
                    System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)
                    System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam)
                    [Native to Managed Transition]
                    user32.dll!7791d313()
                    user32.dll!778fe8da()
                    user32.dll!778fe234()
                    user32.dll!778fdfe0()
                    System.Windows.Forms.ni.dll!68c12f2c()
                    [Managed to Native Transition]
                    System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason, int pvLoopData)
                    System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context)
                    System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context)
                    System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm)
                    him.exe!View.Program.Main()
                    [Native to Managed Transition]
                    mscoreei.dll!71f6d93b()
                    mscoree.dll!71fedd65()
                    kernel32.dll!747b62c4()
                    ntdll.dll!77ac1f69()
                    ntdll.dll!77ac1f34()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...