使没有窗户/命令行应用程序回报,但继续执行的背景是什么意思
问题说明
我在使用.NET编写一个命令行应用程序。该应用程序本身是相当简单的,但它必须同步连接到Web服务,这反过来又连接到Oracle数据库,和的的作品是喜欢采取他们的时间。
I'm writing a command-line application in .Net. The app itself is fairly simple, but it has to connect synchronously to a web-service, which in turn has to connect to a Oracle database, and those pieces are fond of taking their time.
有没有一种简单的方法(没有将我的应用程序的EXE二)继续执行,但仍然得到执行命令提示符?
Is there a straightforward way (without dividing my app exe in two) to continue executing but nonetheless yield execution to the command prompt?
这是Windows系统,因此没有&放大器;。此外,我不能使用的cmd.exe的开始cmdlet的。
It's Windows, so no "&". Also, I cannot use cmd.exe's "start" cmdlet.
正确答案
我不相信这是可能不会从你的应用程序中运行一个后台进程。然而,一个相当干净的方法,这样做可能会修改你的主要方法,像这样:
I don't believe it's possible without running a background process from your application. However, a fairly clean way to do so might be to modify your Main method like so:
static void Main(string[] args)
{
if (args.Length > 0 && args[0] == "run")
{
//actually run your application here
}
else
{
//create another instance of this process
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = Assembly.GetExecutingAssembly().Location;
info.Arguments = "run";
info.UseShellExecute = false;
info.CreateNoWindow = true;
Process.Start(info);
}
}
类似的东西反正只是写这关我的头顶。基本上,它创建相同的可执行文件的新实例,但新工艺看到运行命令行参数和做的工作,而不是生成一个新的实例。设置我的选择应该允许的衍生进程打印到现有的控制台也。
Something like that anyway, just writing this off the top of my head. Basically, it creates a new instance of the same executable, but the new process sees the "run" command line argument and does the work rather than spawning a new instance. Setting the options I have "should" allow the spawned process to print to the existing Console as well.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcgckei
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20