在无模式模式下调用表单时分派消息 [英] Dispatch messages when call a form in modeless mode

查看:67
本文介绍了在无模式模式下调用表单时分派消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我如何获得一个名为无模式"的表单来响应您的消息,同时点击被称为执行其他任务的表单?
示例代码:

报告代表=新报告();
rep.Show(this);
RoutineX();
rep.Close();

我希望在运行例程"RoutineX"时,将执行"rep"形式的消息.

真诚的

Ricardo Tozzi.

Hey, how do I get a form called in "Modeless" to respond to your messages while tapping the form that called you perform another task?
Sample code:

Report rep = new Report ();
rep.Show (this);
RoutineX ();
rep.Close ();

I wish that while the routine "RoutineX" was running, the messages of the form "rep" to be performed.

Sincerely,

Ricardo Tozzi.

推荐答案

此处应从UI类中删除功能业务逻辑"代码的分离. 如果创建一个类来管理所有数据和功能,则此类可以简单地引发系统中任何形式都可以处理的事件.
主要形式将包含对此数据管理对象的实例的引用,然后将该引用传递给报表,然后报表将在报表构建过程中绑定到数据管理对象的事件中.从数据管理对象中运行RoutineX()时,它可以调用报表对象将响应的事件. RoutineX()完成处理并返回后,父窗体仍然可以像现在一样简单地关闭报表.
This is where the separation of functional "business logic" code should be removed from the UI classes.
If you create a class to manage all the data and functionality, then this class could simply raise events that any form in the system can handle.
The main form would hold a reference to an instance of this data management object and then pass that reference on to the report which will then tie into events from the data management object during the reports construction. When RoutineX() is run from within the data management object, it can call events that the report object will respond to. When RoutineX() completes its process and returns, the parent form can still simply close the report as you do now.


问题在于,仅在处理了实际消息之后才处理消息.
就您而言,所有消息将是在完成实际方法(可能是单击)之后的处理.

为了解决该问题,有许多技术.使用线程(由任务或完整线程间接运行)运行RoutineX,将使实际方法完成",并在执行时处理新消息.

但是随后您将需要处理线程同步问题.

如果您想尝试,请致电:
ThreadPool.QueueUserWorkItem(RoutineX);

即使您不使用RoutineX,也需要使它接收类型为object的参数.这将使例程在另一个线程中运行.
The problem is that messages are only processed after the actual message is processed.
In your case, all messages will be processes after finishing the actual method (probably a click).

To solve that problem there are many techniques. Using a thread (be it indirectly by a task or a full thread) to run RoutineX will allow the actual method to "finish", allowing new messages to be processed, while it executes.

But then you will need to deal with Thread synchronization issues.

If you want to try, call:
ThreadPool.QueueUserWorkItem(RoutineX);

You will need to make RoutineX receive an argument of type object even if you don''t use it. This will make routinex run in another thread.


这篇关于在无模式模式下调用表单时分派消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆