是否可以在任务之间发送消息(OmniThreadLibrary)?
我的应用程序将有多个任务来执行各种操作。
所有任务都在 FormCreate 中创建并在 FormDestroy 中终止,只要应用程序运行,它们就始终运行。
主线程的唯一目的是处理用户 I/O 并将用户输入发送到适当的任务或接收要在主窗体中显示的任务信息。
任务之间必须传输数据。
示例:
我将让任务 A 进行数据处理。
它将把一些结果发送到主线程进行显示。
它还必须向任务 B 发送一些(其他)数据,任务 B 会将数据传输到另一台 PC。
任务 C 将从硬件设备接收一些数据,并且必须将此数据发送给任务 A 进行处理。
等等...
据我所知,到目前为止,使用 OmniThreadLibrary 发送消息始终是在任务和创建该任务的线程之间(主线程和任务 A,或主线程和任务 B)。
如何在任意两个任务之间直接发送消息?
或者到目前为止我的方法有什么问题并且应该完全不同吗?
My app will have several tasks for various actions.
All tasks are created in FormCreate and terminated in FormDestroy, they are always running as long as the app is running.
The main thread's only purpose is to handle user I/O and send user inputs to the appropriate task or receive task information to be displayed in the main form.
There will be data that has to be transferred between tasks.
Example:
I will have task A doing data processing.
It will send some of it's results to the main thread for displaying.
It will also have to send some (other) data to task B, which will transfer the data to another PC.
Task C will receive some data from a hardware device and has to send this data to task A for processing.
etc...
As I understand so far, sending messages with OmniThreadLibrary is always between the task and the thread that created the task (Main thread and task A, or Main thread and task B).
How can I send messages directly between any two tasks?
Or is there any problem with my approach so far and it should be done completely different?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能的。您必须在所有者中创建一个通信通道并将其传递给这两个任务。然后在任务中调用 Task.RegisterComm 来注册此通信通道。从那时起,在此通道上接收到的所有消息都将使用标准 OmniThreadLibrary 机制进行分派(即,就像它们是从所有者发送的一样)。
有关示例,请参见演示 08_RegisterComm。
Possible. You have to create a communication channel in the owner and pass it to both tasks. In the task you then call Task.RegisterComm to register this communication channel. From that point onwards, all messages received on this channel will be dispatched using the standard OmniThreadLibrary mechanisms (i.e. exactly as if they would be sent from the owner).
See demo 08_RegisterComm for an example.