foreach循环的线程 [英] Made thread of foreach loop

查看:94
本文介绍了foreach循环的线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,该应用程序运行8个汉字(随机开始),如果找到一个符合PasswordPolicy的单词,则停止运行,现在我该如何使它成为多线程的?

I am writing an application that runs through 8chracter words(starting randomly) and stops if a word had been found that complies with the PasswordPolicy, now how do I make this multithreaded?

foreach (string word in GetWords(8))
{
  if (CheckPasswordPolicy(word))
   {
    MessageBox.Show(word);
     return;
   }
}



问候,
Wim.



Greets,
Wim.

推荐答案

使用BackgroundWorker对象.我会给您特定的代码,但是互联网上有很多示例.只需使用Google即可找到它们.
Look into using a BackgroundWorker object. I would give you specific code, but there are plenty of examples on the internet. Just use google to find them.


如果有1个线程找到了我的单词,我该如何使用10条线程并停止所有操作?

来自JSOP:运行多个线程来搜索同一列表是毫无意义的.实际上,使用线程来完成此操作似乎是一个有问题的设计决策,因为我认为您正在响应用户输入密码来遍历列表.您可能不希望他在对列表进行密码检查之前继续操作,所以为什么要创建所有开销并通过将其放在线程中来工作?
How can I use let''s say 10 threads and stop everything if 1 thread finds my word?

From JSOP: It would be fairly pointless to run multiple threads to search through the same list. In fact, using a thread to do this at all seems like a questionable design decision, because I assume that you''re running through the list in response to the user entering a password. You probably don''t want him to proceed until the password has been checked against the list, so why create all that overhead and work by putting it in a thread?


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

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