【发布时间】:2019-01-22 00:00:28
【问题描述】:
我们的 Winforms 模块是一个 WCF 客户端,在处理 WM_PAINT 时它调用 WCF 服务的双向方法。我期待它等待回复;但是会发生递归,导致嵌套的 WM_PAINT,随之而来的是各种问题。 现在我意识到 WM_PAINT 处理程序可能不是通过线路调用的最佳位置,但上述行为首先是如何可能的呢? WCF 客户端线程在等待双向调用的回复时不应该阻塞吗? UI 模块使用了两个第三方库,所以我不确定谁应该为所发生的事情负责。恕我直言,在 WM_PAINT 中通过网络调用不是好的,但它本身不应该引起递归。 这是堆栈:
<Our code – recursion!>
System.dll!System.ComponentModel.TypeConverter.ConvertToString(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
SmartPropertyGrid.dll!VisualHint.SmartPropertyGrid.PropertyValue.ConvertValueToDisplayedString(object value)
SmartPropertyGrid.dll!VisualHint.SmartPropertyGrid.PropertyValueIndirect.HasMultipleTexts(out string text, out bool textIsExceptionText)
SmartPropertyGrid.dll!VisualHint.SmartPropertyGrid.PropertyValue.HasMultipleTexts()
SmartPropertyGrid.dll!VisualHint.SmartPropertyGrid.Property.Draw(System.Drawing.Graphics graphics, System.Drawing.Rectangle itemRect, VisualHint.SmartPropertyGrid.PropertyVisibleDeepEnumerator enumSelf)
SmartPropertyGrid.dll!A.c84db8915b8e0ce02a23aa50484601540.OnPaint(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)
SmartPropertyGrid.dll!A.c84db8915b8e0ce02a23aa50484601540.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]
[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(System.TimeSpan timeout, bool exitContext)
System.ServiceModel.Internals.dll!System.Runtime.TimeoutHelper.WaitOne(System.Threading.WaitHandle waitHandle, System.TimeSpan timeout)
System.ServiceModel.dll!System.ServiceModel.Dispatcher.DuplexChannelBinder.SyncDuplexRequest.WaitForReply(System.TimeSpan timeout)
System.ServiceModel.dll!System.ServiceModel.Dispatcher.DuplexChannelBinder.Request(System.ServiceModel.Channels.Message message, System.TimeSpan timeout)
System.ServiceModel.dll!System.ServiceModel.Channels.ServiceChannel.Call(string action, bool oneway, System.ServiceModel.Dispatcher.ProxyOperationRuntime operation, object[] ins, object[] outs, System.TimeSpan timeout)
System.ServiceModel.dll!System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(System.Runtime.Remoting.Messaging.IMethodCallMessage methodCall, System.ServiceModel.Dispatcher.ProxyOperationRuntime operation)
System.ServiceModel.dll!System.ServiceModel.Channels.ServiceChannelProxy.Invoke(System.Runtime.Remoting.Messaging.IMessage message)
mscorlib.dll!System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(ref System.Runtime.Remoting.Proxies.MessageData msgData, int type)
[Native to Managed Transition]
[Managed to Native Transition]
[Managed to Native Transition]
<Our code>
【问题讨论】:
-
您在 Paint Message 中调用 WCF 服务?天哪,为什么
-
无论如何,这至少可以说很奇怪,这里没有足够的信息来帮助你。您将需要进行一些取证调试并找出您正在做的事情的真实性质
-
@TheGeneral:这是一个遗留代码,我将对其进行改进/重构。
标签: c# winforms wcf recursion two-way