单实例应用程序和批处理文件 [英] Single-instance applications and batch files

查看:117
本文介绍了单实例应用程序和批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果从批处理文件运行配置为单实例操作的应用程序,是否有什么好方法来控制批处理文件等待多长时间以及将返回什么错误代码?我能想到的最好方法是有一对程序:一个运行单实例的窗口应用程序,一个运行多实例的控制台应用程序.运行时,控制台应用程序将使用包含类似TCP套接字的参数来调用单实例应用程序.然后,单实例应用程序可以传回所需的错误代码以及希望控制台应用程序显示的任何消息.

我的预期用途是批处理文件执行只能执行一项操作的操作.一次并让单实例应用程序对操作进行排序,然后在操作完成后保持运行以显示其状态.

我的目标平台是.net 2.0.

If an application which is configured for single-instance operation is run from a batch file, is there any nice way to control how long the batch file waits and what error code will be returned to it? The best approach I can figure would be to have a pair of programs: a windowed application that runs single-instance, and a console application that runs multi-instance. When run, the console application would invoke the single-instance application with a parameter containing something like a TCP socket. The single-instance application could then pass back the desired error code as well as any messages it would like the console application to display.

My intended use would be that the batch files do operations which may only be done one at a time, and to have the single-instance application sequence the operations, and then remain up after the operations are complete to show their status.

My target platform is .net 2.0. Any ideas?

推荐答案



单实例应用程序从来不是真正的单实例.最好在启动第二个,第三个或任何实例后,检测到它不是第一个,然后再次退出,希望将其工作传递给第一个实例后,也许可以通过管道将其命令行发送出去.

如何将单实例"设置为:
-检测到它不是第一个;
-将作业发送到第一个实例;
-而不是立即退出,等待完成.

以这种方式执行批处理文件而不必知道,它们似乎总是在与单实例应用程序通信.

BTW:显然您可以使用Main()方法的返回值作为批处理/DOS退出代码.

:)

Hi,

a single-instance app never really is single-instance. At best the second, third or whatever instance gets launched, detects it isn''t number one, and exits again, hopefully after passing its work to the first instance, maybe by sending its command line through a pipe.

how about you make the "single-instance" such that it:
- detects it isn''t the first;
- sends the job to the number one instance;
- instead of exiting right away, waits for completion.

Doing it that way your batch files don''t have to be aware, they would always seem to be talking to the single-instance app.

BTW: obviously you can use the Main() method''s return value as the batch/DOS exit code.

:)


MoNUmy zwtbxuwmitra ,[url = http://cbjuxwnxmvsy.com/] cbjuxwnxmvsy [/url],[link = http://tucrbzulnook.com/] tucrbzulnook [ /link],http://zzzelknyktmt.com/
MoNUmy zwtbxuwmitra, [url=http://cbjuxwnxmvsy.com/]cbjuxwnxmvsy[/url], [link=http://tucrbzulnook.com/]tucrbzulnook[/link], http://zzzelknyktmt.com/


这篇关于单实例应用程序和批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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