问题描述
嘿伙计们,
我遇到了一些问题,DragDrop.DoDragDrop有时会抛出以下错误(错误代码转换为COR_E_FAILFAST),只会在调用FailFast,因此无法阻止软件关闭。
I'm having some trouble with DragDrop.DoDragDrop sometimes it throws the following error (the error code translate to COR_E_FAILFAST) that only occurs when the FailFast is called, so its impossible to prevent the software to be closed.
COMException比这更频繁地抛出FatalExecutionEngineError但我只是记录并忽略它。 FatalExecutionEngineError很少见并且要重现我必须在它发生之前多次开始拖动,但是有时候
发生得非常快,就像一两次尝试一样。
The COMException is throw more frequentily than this FatalExecutionEngineError but i just log it and ignore it. The FatalExecutionEngineError is kind of rare and to reproduce i have to start the drag many time before it happens, but some time it happens really fast like one or two tries.
托管调试助手'FatalExecutionEngineError':'运行时遇到了致命错误。错误的地址是0x610de28b,在线程0xc90上。错误代码是0x80131623。此错误可能是CLR中的错误,也可能是用户代码的不安全或不可验证的
部分中的错误。此错误的常见来源包括COM-interop或PInvoke的用户封送错误,这可能会破坏堆栈。'
Managed Debugging Assistant 'FatalExecutionEngineError' : 'The runtime has encountered a fatal error. The address of the error was at 0x610de28b, on thread 0xc90. The error code is 0x80131623. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.'
背后的代码
private void PictureBoxBorder_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
_isDragging = true;
}
private void PictureBoxBorder_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
_isDragging = false;
}
private void PictureBox_MouseLeave(object sender, MouseEventArgs e)
{
startDragging(sender, e);
}
private bool _isDragging = false;
private void PictureBoxBorder_PreviewMouseMove(object sender, MouseEventArgs e)
{
startDragging(sender, e);
}
private void startDragging(object sender, MouseEventArgs e)
{
// Get the current mouse position
Point mousePos = e.GetPosition(null);
Vector diff = startPoint - mousePos;
if (_isDragging && e.LeftButton == MouseButtonState.Pressed &&
(Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
{
var border = sender as Border;
// Initialize the drag & drop operation
if (border != null)
{
DataObject dragData;
if (IsPlayback)
{
dragData = new DataObject("playback", CameraDisplay.DataContext);
}
else
{
dragData = new DataObject("device", CameraDisplay.DataContext);
}
try
{
DragDrop.DoDragDrop(CameraDisplay, dragData, DragDropEffects.Move);
}
catch (COMException ex)
{
_logger.Error("DragAndDrop Error on camera display: " + ex.Message);
}
}
}
}
视图:
<Border MouseDown="PictureBox_MouseDown" MouseMove="PictureBox_MouseMove" MouseUp="PictureBox_MouseUp"
MouseWheel="PictureBox_MouseWheel" MouseLeave="PictureBox_MouseLeave" Background="Transparent"
Name="PictureBoxBorder" PreviewMouseLeftButtonDown="PictureBoxBorder_PreviewMouseLeftButtonDown"
PreviewMouseLeftButtonUp="PictureBoxBorder_PreviewMouseLeftButtonUp"
PreviewMouseMove="PictureBoxBorder_PreviewMouseMove" Tag="{Binding Channel}">
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<DataTrigger Binding="{Binding Channel}" Value="{x:Null}">
<Setter Property="Visibility" Value="Hidden"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<controls:HandleControl Panel.ZIndex="1000" Grid.Row="0" x:Name="PictureBox" ReadyCommand="{Binding HandleReadyCommand}"/>
</Border>
可能相关的一件事是HandleControl,它是HwndHost的一个实现:
One thing that probably is relevant is the HandleControl, that is a implementation of the HwndHost:
public class HandleControl : HwndHost
{
internal const int
WS_CHILD = 0x40000000,
WS_VISIBLE = 0x10000000,
LBS_NOTIFY = 0x00000001,
HOST_ID = 0x00000002,
LISTBOX_ID = 0x00000001,
WS_VSCROLL = 0x00200000,
WS_BORDER = 0x00800000,
SS_GRAYRECT = 0x00000005,
SS_CENTER = 0x00000001,
SS_CENTERIMAGE = 0x00000200,
SS_REALSIZECONTROL = 0x00000040,
SS_BITMAP = 0x0000000E,
SS_BLACKRECT = 0x00000004,
SS_BLACKFRAME = 0x00000007,
WS_EX_TRANSPARENT = 0x00000020;
private const int WM_CTLCOLORSTATIC = 0x0138;
const uint WM_SETTEXT = 0x000C;
const uint STM_SETIMAGE = 0x0172;
public const int LWA_ALPHA = 0x2;
public ICommand ReadyCommand
{
get { return (ICommand)GetValue(ReadyCommandProperty); }
set { SetValue(ReadyCommandProperty, value); }
}
// Using a DependencyProperty as the backing store for ReadyCommand. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ReadyCommandProperty =
DependencyProperty.Register("ReadyCommand", typeof(ICommand), typeof(HandleControl), new PropertyMetadata(null, OnReadyCommandChanged));
IntPtr hwndHost = IntPtr.Zero;
int hostHeight, hostWidth;
protected delegate IntPtr WndProcDelegate(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
public HandleControl()
{
//it is set to 1 but it can be changed on the future
//today the height and with can be set to 1 because it streches to fit the camera space
hostHeight = 1;
hostWidth = 1;
}
[DllImport("user32.dll", EntryPoint = "CreateWindowEx", CharSet = CharSet.Unicode)]
internal static extern IntPtr CreateWindowEx(int dwExStyle,
string lpszClassName,
string lpszWindowName,
int style,
int x, int y,
int width, int height,
IntPtr hwndParent,
IntPtr hMenu,
IntPtr hInst,
[MarshalAs(UnmanagedType.AsAny)] object pvParam);
[DllImport("user32.dll", EntryPoint = "DestroyWindow", CharSet = CharSet.Unicode)]
internal static extern bool DestroyWindow(IntPtr hwnd);
[DllImport("kernel32.dll", EntryPoint = "GetLastError", CallingConvention = CallingConvention.StdCall)]
public static extern uint GetLastError();
protected override HandleRef BuildWindowCore(HandleRef hwndParent)
{
hwndHost = IntPtr.Zero;
hwndHost = CreateWindowEx(0, "static", "",
WS_CHILD | WS_VISIBLE | SS_BLACKRECT,
0, 0,
hostWidth, hostHeight,
hwndParent.Handle,
(IntPtr)HOST_ID,
IntPtr.Zero,
0);
if (ReadyCommand != null)
{
ReadyCommand.Execute(hwndHost);
}
return new HandleRef(this, hwndHost);
}
protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
handled = false;
return IntPtr.Zero;
}
protected override void DestroyWindowCore(HandleRef hwnd)
{
DestroyWindow(hwnd.Handle);
}
private static void OnReadyCommandChanged(object sender, DependencyPropertyChangedEventArgs e)
{
HandleControl control = sender as HandleControl;
if (control != null)
{
if (control.ReadyCommand != null && control.hwndHost != IntPtr.Zero)
{
control.ReadyCommand.Execute(control.hwndHost);
}
}
}
}
推荐答案
根据你的问题与WPF更相关,我将把线程移到 WPF论坛以获得合适的支持。
According to your question is more related to WPF, I will move the thread to WPF Forum for suitable support.
Visual C#讨论并询问C#编程语言,IDE,库,示例和工具。如果您有一些语法或代码错误,请随时与我们联系。我们会尽力为您提供解决方案。
The Visual C# discuss and ask the C# programming language, IDE, libraries, samples and tools . If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution.
此致,
Neil Hu
这篇关于DoDragDrop FatalExecutionEngineError 0x80131623(COR_E_FAILFAST)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!