如何同时运行这两个线程 [英] How to run these two threads simultaneously

查看:131
本文介绍了如何同时运行这两个线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的代码



公共课计划

{

public static void Main(string [ ] args)

{

string [] filePaths = Directory.GetFiles(@c:\\images\\);

for(int i = 0; i< filepaths.length;>

{

Thread thread1 = new Thread(()=> getImageData(filePaths [ i],i));

thread1.Start();

}

}

public static void getImageData(string filename,int x)

{

//过程图片

}



}



我想同时处理两个图像以最小化处理时间。上面的代码只启动所有线程但不能给出输出。如果我使用thread1 .Join()它首先完成一个线程并启动另一个线程。我想同时运行多个线程。请给我解决方案。解决方案

访问这里...



http://stackoverflow.com/questions/266168/simple-example-of-threading-in-c [ ^ ]









http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html [ ^ ]


Below is my code

public class Program
{
public static void Main(string[] args)
{
string[] filePaths = Directory.GetFiles(@"c:\\images\\");
for (int i = 0; i<filepaths.length;>
{
Thread thread1 = new Thread(() => getImageData(filePaths[i], i));
thread1.Start();
}
}
public static void getImageData(string filename, int x)
{
//Process image
}

}

I want to process two images simultaneously to minimize processing time. Above code only starts all the thread but can not give output.If I use thread1.Join() it completes one thread first and starts another. I want to run multiple threads simultaneously. Please give me solution for this.

解决方案

visit here...

http://stackoverflow.com/questions/266168/simple-example-of-threading-in-c[^]

or


http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html[^]


这篇关于如何同时运行这两个线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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