【问题标题】:Is there a way to pause a ActiveX Control (MapPoint) or run DoDragDrop async?有没有办法暂停 ActiveX 控件 (MapPoint) 或异步运行 DoDragDrop?
【发布时间】:2011-01-18 22:01:34
【问题描述】:

我目前正在开发一个带有 MapPoint-Control 的应用程序,这让我很难过。 从线程启动DoDragDrop(mappoint 也使用该线程)后,我总是在几秒钟后从 mappoint 收到一个对话框,说我的表单没有反应。

MapPoint-Control 是一个ActiveX-Control,使用控件MapPoint 在后台启动并在不同的线程中运行。我认为 Mappoint 尝试更新控件但超时。

有没有办法在不同的线程中运行DoDragDrop,以便 MapPoint 从主线程获得响应。 或者是否可以告诉 MapPoint 我的表单当前已暂停。或者我可以以某种方式暂停 MapPoint?

我尝试使用表单控件和 MapPoint-Control 运行 DoDragDrop

【问题讨论】:

    标签: c# drag-and-drop activex mappoint


    【解决方案1】:

    我找到了问题。

    我在BeforeClick-事件中解雇了DoDragDrop。 MapPoint 可能会等待事件回调,但没有得到一个,因为DoDragDrop 会一直保持事件直到鼠标被释放。

    现在我编写了一个事件,它启动 DoDragDrop 事件异步到 MapPoint BeforeClick-Event。

    代码:

    
    public event InitDragDropHandler InitDragDrop;
    public delegate void InitDragDropHandler(object sender, object data);
    
    public main()
    {
        this.InitDragDrop += new InitDragDropHandler(main_InitDragDrop);
    }
    
    void mappoint_BeforeClick(object sender, AxMapPoint._IMappointCtrlEvents_BeforeClickEvent e)
    {
        if (InitDragDrop != null)
        {
            this.BeginInvoke(new ThreadStart(() =>
                {
                    InitDragDrop(mappoint, pps);
                }));
        }
    }
    
    
    void main_InitDragDrop(object sender, object data)
    {
        ((Control)sender).DoDragDrop(data, DragDropEffects.Copy);
    }
    

    【讨论】:

    • 这是否意味着 MapPoint 控件在其自己的线程上?我有点惊讶这行得通。我在自己的线程上使用了 MapPoint 应用程序和其他东西,但你必须小心;而且 Windows 不喜欢多个线程使用相同的控件。
    • 从线程启动 DoDragDrop 后,mappoint 也使用了,...我认为他的意思是在同一个线程中
    • @winwaed:就像 edze 说的,mappoint 控件在主线程中运行,但是由于 begininvoke,在 mappoints BeforeClick 事件完成后会触发 InitDragDrop 事件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-18
    • 2022-01-09
    • 2019-01-12
    • 1970-01-01
    • 1970-01-01
    • 2010-10-11
    • 1970-01-01
    相关资源
    最近更新 更多