如何在批处理文件中实现多线程? [英] How can I realize Multithreading in Batch-Files?

查看:815
本文介绍了如何在批处理文件中实现多线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个在不同线程中调用其他2个批处理文件的批处理文件.每个线程应在处理器的另一个内核上执行.
如何实现呢?

在此先感谢您的帮助!

I want to create a batch-file that calls 2 other batch-files in different threads. Each thread shall be performed on another core of the processor.
How to realize this?

Thanks in advance for any help!

推荐答案

如果可以使用PowerShell多线程确实是一种选择.我在这里找到了一个示例: http://blog.isaacblum.com/2010/01/22 /powershell-multithreading-omg/ [ ^ ].谷歌搜索+ PowerShell +多线程处理可产生111K的结果.我相信您会发现更多示例.

干杯!
If it were OK for you to use PowerShell multithreading would indeed be an option. I found an example here: http://blog.isaacblum.com/2010/01/22/powershell-multithreading-omg/[^]. Googling +PowerShell +Multithreading yields 111K results. I''m sure you''ll find more examples as you come along.

Cheers!


启动同一控制台应用程序的多个实例. Windows下运行的每个应用程序都存在于其自己的线程中.

除此之外,您不必烦恼分配核心亲和力,因为与Windows 7结合的.Net应用程序将非常有效地独自使用系统的体系结构.
Start multiple instances of the same console app. Each running application under Windows exists within its own thread.

Beyond that, you shouldn''t have to mess with assigning core affinity because .Net apps combined with Windows 7 will make the most efficient use of your system''s architecture pretty much on its own.


我建​​议您根据需要删除批处理文件.这不是足够的技术.问题甚至没有启动几个进程,问题是启动它们时无法访问进程句柄.使用CreateProcessEx(Windows API)或Process.Create(.NET)进行编程可以完全解决此问题.您可以使用一些数据对象来存储应用程序的列表/顺序或您可能需要的任何元数据. (有时也可以将代码嵌入您的代码中,但这只是一个单独的讨论话题.)

—SA
I suggest with your requirements you should eliminate batch files. This is not adequate technique. The problem is not even starting several processes, the problem is having no access to the process handles when they are started. Programming using CreateProcessEx (Windows API) or Process.Create (.NET) solves this problem completely. You can use some data objects to store list/sequence of applications or any meta-data you may possibly need. (Embedding the code in yours is also sometimes possible, but it''s a matter of a separate thread of discussion.)

—SA


这篇关于如何在批处理文件中实现多线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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