关于buttonclicked事件 [英] About buttonclicked event

查看:419
本文介绍了关于buttonclicked事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在按钮点击事件上调用3个.exe文件

它们必须按顺序填充

在完成第一个.exe文件后将加速。<完成第二个exe后,
将会加速。



如果这三个exe文件中的任何一个不起作用,它应该填充消息框(显示错误)



如何做到这一点?我用过ShellExecute()



谢谢!!



I want to call 3 .exe files on button clicked event
they have to be populate in sequence
after compliting first .exe file second will poped up.
after completing 2nd exe 3rd will be poped up.

if any of these 3 exe files doen''t work it should populate message box (showing "error ")

How to do that? i have used ShellExecute()

Thank you !!

ShellExecute(NULL, ("open"),("1.exe"),NULL,NULL,SW_SHOWNORMAL);
ShellExecute(NULL, ("open"),("2.exe"),NULL,NULL,SW_SHOWNORMAL); 
ShellExecute(NULL, ("open"),("3.exe"),NULL,NULL,SW_SHOWNORMAL);

推荐答案

如果你使用每个 ShellExecute 返回的进程句柄,你可以这样做;然后你可以使用函数 WaitForMultipleObjects

http://msdn.microsoft.com/en-us/library/windows/desktop/ms687025%28v=vs.85%29.aspx [ ^ ]。



此函数调用将是阻塞调用。您的调用线程将设置为等待状态,直到所有三个进程终止。在这种等待状态中,调用线程将被关闭,并且不会被调度回执行,直到某些事件唤醒,例如超时或满足条件(所有进程终止)。这样,等待将花费零CPU时间,这很好。



因为这样的调用是阻塞的,根据经验,调用线程不应该是UI线程。也就是说,如果您的应用程序是Windowed UI应用程序,则需要创建一个单独的线程,您可以在其中执行所有阻塞调用。如果你可以合理地期望所有三个子进程都可以在很短的时间内完成,你甚至可以在UI线程中完成它,但我不会这样做。



此外,我会避免使用 ShellExecute 并且根本没有任何单独的进程。将它们变成DLL以供进程内使用是最好的。你看,这些过程非常孤立;因此,您从父进程访问子进程的权限非常有限。你可以等待它的终止;如果这是一个简单的仅控制台进程,您可以将其输出重定向到您的进程并处理它;这就是你几乎所能做的一切。只有通过某些IPC机制专门设计,不同的流程才能有效地协作。我确定这不是你的情况,否则你不会问这个问题。



-SA
You can do it, if you use the process handle returned by each ShellExecute; then you can use the function WaitForMultipleObjects:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms687025%28v=vs.85%29.aspx[^].

This function call will be a blocking call. Your calling thread would be set to wait state until all three processes are terminated. In this wait state, the calling thread will be switched off and not scheduled back to execution until waken up by some event, such as time out or when the condition (all processes are terminated) is satisfied. This way, the wait will spend zero CPU time, which is good.

As such call is blocking, as a rule of thumb, the calling thread should not be a UI thread. That said, if your application is a Windowed UI application, you will need to create a separate thread where you can do all the blocking calls. If you can reasonably expect that all three child processes can be completed in a very short period of time, you could do it even in a UI thread, but I wouldn''t do it.

Moreover, I would avoid using ShellExecute and having any separate processes at all. It would be the best to turn them into DLL for in-proc use. You see, the processes are very well isolated; so you have a very limited access of control over a child process from your parent process. You can wait for its termination; if this is a simple console-only process, you can redirect its output to your process and handle it; and that''s nearly all you can do. The different processes can effectively collaborate only if they are designed specially to do so, via some IPC mechanisms. I''m sure this is not your case, otherwise you would not ask this question.

—SA


这篇关于关于buttonclicked事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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