简体   繁体   English

线程,队列和严重的头痛

[英]Threads, Queue and a serious headache

I am making a program for days but nothing seems to be working. 我正在编写程序几天,但似乎没有任何效果。 I want to run (n threads=user sepecified threads ie 1-100) on a listview which has 1st field as email (the list is of 10000 records). 我想在具有第一个字段作为电子邮件的listview上运行(n个线程=用户分离的线程,即1-100)(列表是10000条记录)。 Now I want to verify each email and add on the 2nd column the thread id and on the third column the result whether the email is valid or not can anybody help me? 现在,我要验证每封电子邮件,并在第二列上添加线程ID,并在第三列上添加结果(无论该电子邮件是否有效),有人可以帮助我吗? With some code and explanation. 带有一些代码和解释。 thanx 感谢名单

First of all, don't use a ListView as a datastructure. 首先,不要将ListView用作数据结构。 Bind it to some List<MyClass> . 将其绑定到某些List<MyClass>

Then run your Threads on the ThreadPool (<= .NET 3.5) or using Tasks (.NET4). 然后在ThreadPool(<= .NET 3.5)或使用Tasks(.NET4)上运行线程。

The learn about accessing your List<> in a thread-safe way. 了解如何以线程安全的方式访问List <>。 And then update your ListView using Control.Invoke(), or from a Timer 然后使用Control.Invoke()或从计时器更新ListView

This sounds like a task for the Task Parallel Library . 这听起来像Task Parallel Library的一项任务。 Rather than managing your threads by hand, it provides you with higher-level constructs which will properly use the thread pool and the hardware you have available, and parallelize work. 它为您提供了更高级别的构造,而不是手动管理线程,这些构造将正确使用线程池和可用的硬件,并使工作并行化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM