制作一个VB6应用程序一个C#kill事件? [英] Making a C# kill event for a vb6 app?

查看:309
本文介绍了制作一个VB6应用程序一个C#kill事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个VB6应用程序,对于一个很长很长的时间处理。直接杀死它是不可行的,所以我想设置一些标志在VB6应用程序。如果在我的C#应用​​程序,我决定将它关闭,我想切换这个标志让VB6应用程序知道关闭已请求。现在,我还需要一些名为因为会有几起转化为ActiveX EXE文件的VB6应用程序。没有人有任何想法如何实现这样的事情?工作流程遵循以下

I have a VB6 app that processes for a very, very long time. Killing it directly is not feasible, so I would like to set some sort of flag in the VB6 app. If in my C# app I decide to shut it down, I would like to toggle this flag to let the VB6 app know that a shutdown has been requested. Now, I also need something that is named because there will be several of the VB6 apps spun up as activex exes. Does anyone have any idea how to implement something like this? The workflow follows below

C#应用程序 - 旋转加速多张VB6 activex.exes在单独的线程,初始化的东西(以下称为标志),我可以在C#中的变化,并调用DoStuff命令,这需要很长的时间来恢复应用程序

C# app - Spin up mulitple VB6 activex.exes in separate threads, Initialize the app with something (henceforth called a flag) I can change in C#, and call the DoStuff command, which takes a very long time to return.

VB6 - 获取具有标志初始化命令。 DoStuff被调用。在DoStuff循环,它会检查标志仍设置。

VB6 - Gets the initialize command with the flag. DoStuff gets called. In the DoStuff loop, it checks if the flag is still set.

C# - 由标志设置为另一种状态杀死项目

C# - Kill the project by setting the flag to another state

任何想法?

推荐答案

下面是用VB6客户端和服务器VB6异步后台处理pretty标准方案。 (比如,它是于丹Appleman的和微软的 VB6样本的。)我认为它应该为一个C#客户端工作了。

Here is a pretty standard scheme for asynchronous background processing with VB6 clients and VB6 servers. (For instance it's in Dan Appleman's book and Microsoft's VB6 samples.) I think it should work for a C# client too.


  • 的VB6的ActiveX EXE的对象应揭露事件CheckQuitDoStuff()。这需要一个布尔的ByRef叫退出。

  • 客户端中的ActiveX EXE对象调用StartDoStuff。这个程序启动隐藏窗体上的计时器和立即返回。这疏导调用线程。计时器的时间间隔很短,以便迅速计时器事件触发。

  • 定时器事件处理程序禁用定时器,然后回调到ActiveX对象DoStuff方法。这将开始漫长的处理。

  • 定期的DoStuff方法引发CheckQuitDoStuff事件。客户端的事件处理程序检查的特殊标志,并设置退出真,如果有必要中止。然后DoStuff中止如能早期退出的计算并返回为True。

  • The VB6 ActiveX EXE object should expose an event CheckQuitDoStuff(). This takes a ByRef Boolean called Quit.
  • The client calls StartDoStuff in the ActiveX EXE object. This routine starts a Timer on a hidden form and immediately returns. This unblocks the calling thread. The Timer interval is very short so the Timer event fires quickly.
  • The Timer event handler disables the Timer, and then calls back into the ActiveX object DoStuff method. This begins the lengthy processing.
  • Periodically the DoStuff method raises the CheckQuitDoStuff event. The client's event handler checks the special flag and sets Quit True if it's necessary to abort. Then DoStuff aborts the calculation and returns early if Quit is True.

该计划意味着客户实际上并不需要是多线程的,因为调用线程不会阻止,而DoStuff正在发生的事情。最棘手的部分是确保DoStuff提出在适当的间隔事件 - 太长了,当你想你不能不干了:太短暂了,你unecessarily放缓DoStuff。此外,DoStuff退出时,它必须卸载隐藏的形式。

This scheme means that the client doesn't actually need to be multi-threaded, since the calling thread doesn't block while "DoStuff" is happening. The tricky part is making sure that DoStuff raises the events at appropriate intervals - too long, and you can't quit when you want to: too short, and you are slowing down DoStuff unecessarily. Also, when DoStuff exits, it must unload the hidden form.

如果DoStuff没有实际管理得到被中止之前做的所有的东西,你可以提出不同的事件来告诉客户端,作业已完成。

If DoStuff does actually manage to get all the stuff done before being aborted, you can raise a different event to tell the client that the job is finished.

这篇关于制作一个VB6应用程序一个C#kill事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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