简体   繁体   English

给定System.ExecutionEngineException的GetMessage()

[英]GetMessage() given an System.ExecutionEngineException

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        public static extern
            bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, int vk);
        [DllImport("user32")]
        public static extern
            bool GetMessage(ref Message lpMsg, IntPtr handle, uint mMsgFilterInMain, uint mMsgFilterMax);

        public const int MOD_ALT = 0x0001;
        public const int MOD_CONTROL = 0x0002;
        public const int MOD_SHIFT = 0x004;
        public const int MOD_NOREPEAT = 0x400;
        public const int WM_HOTKEY = 0x312;
        public const int DSIX = 0x36;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            bool r = RegisterHotKey(Handle, 1, MOD_ALT, DSIX);

            if (!r)
            {
                MessageBox.Show("can't do..");
                return;
            }

            Message msg = new Message();

            while (GetMessage(ref msg,IntPtr.Zero, 0, 0))
            {
                if (msg.message == WM_HOTKEY)
                {
                    MessageBox.Show("do work..");
                }
            }


        }
    }


    public class Message
    {
        public int message { get; set; }
    }
}

when the target is pressed, I get the following error: 当按下目标时,出现以下错误:

Exception of type 'System.ExecutionEngineException' was thrown.

what's is this? 这是什么? how to fix this? 如何解决这个问题? Thanks in advance. 提前致谢。

This is doomed to failure. 这注定要失败。 If you write your own message loop it will stop WinForms receiving any messages. 如果编写自己的消息循环,它将停止WinForms接收任何消息。

Instead, override the PreProcessMessage or WndProc functions. 而是改写PreProcessMessageWndProc函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 抛出System.ExecutionEngineException - System.ExecutionEngineException being thrown DBContext 构造函数中的 System.ExecutionEngineException - System.ExecutionEngineException in DBContext Constructor Windows服务的System.ExecutionEngineException - System.ExecutionEngineException With Windows Service Windows 10设备上的System.ExecutionEngineException - System.ExecutionEngineException on Windows 10 device 仅在调试时才发生System.ExecutionEngineException - System.ExecutionEngineException only when debugging 如何找到 System.ExecutionEngineException 异常的来源 - How to find source of System.ExecutionEngineException Exception 为什么此代码抛出System.ExecutionEngineException - Why this code throws System.ExecutionEngineException 附加到 Revit 过程失败并出现 System.ExecutionEngineException - Attach to Revit process fails with System.ExecutionEngineException OpenTK:GLFW.PollEvents() 处的 System.ExecutionEngineException - OpenTK: System.ExecutionEngineException at GLFW.PollEvents() 读取 Azure 密钥保管库会引发异常:System.ExecutionEngineException:“引发了‘System.ExecutionEngineException’类型的异常。” - Reading Azure key vault throws exception: System.ExecutionEngineException: 'Exception of type 'System.ExecutionEngineException' was thrown.'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM