可以使用Threadpool [英] possible to use Threadpool

查看:73
本文介绍了可以使用Threadpool的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


我写了一个应用程序,它可以从数据库中获取电子邮件,并检查它是否是正确的电子邮件(连接到远程数据库)邮件服务器并检查

响应。

我想通过使用多个线程来提高性能。

我可以使用线程池吗? ?我该怎么做呢。

为了开始,我把所有的电子邮件都放在一个数组中。


感谢您的帮助。


daniel

Hi all

I have written a app that gets emails from a DB and checks if it''s a
correct email (connects to the remote mailserver and checks the
response).
I would like to improve the performance with using multiple threads.
can I use a threadpool for this? and how do I have to do this.
For starting i have all emailaddresses in a Array.

thanks for your help.

daniel

推荐答案

你好Daniel Daniel,


DI写的一个从数据库收到电子邮件的应用程序并检查它是否是

Dcorrect电子邮件(连接到远程邮件服务器并检查

Dresponse)。

DI希望通过使用多个线程来提高性能。

Dcan我使用线程池吗?


你可以,但它可以是对于1.1 fw来说不是很好的解决方案,如果你有很多长期运行的任务,因为那里的TP'线程的数量

受限于25线程如果你有多个长期运行的
操作,你会得到被阻塞的线程,等待25个线程中的一个完成

它的工作。


在2.0中你可以设置所需的线程数,但考虑到

25是一般最佳线程数,并且由于上下文切换而克服了负面的b $ b效果


Dand我该怎么做呢。

D开始我有一个数组中的所有emailaddresses。


使用ThreadPool类的样本进入MSDN


---

WBR,

Michael Nemtsev ::博客: http://spaces.live.com/laflour


"有时一个仍然存在忠实于某一事业的原因只是因为它的对手不会因为b b不再是平淡无奇的。 (c)Friedrich Nietzsche
Hello Daniel,

DI have written a app that gets emails from a DB and checks if it''s a
Dcorrect email (connects to the remote mailserver and checks the
Dresponse).
DI would like to improve the performance with using multiple threads.
Dcan I use a threadpool for this?

You could, but it can be not the very good solution for the 1.1 fw if u have
a big number of long runned tasks, because the number of TP''s threads there
are limited by 25 thread, and in case if you have numbers of long-runned
operations u got the blocked threads which wait till one of 25 threads complete
its work.

In 2.0 u can set the desired number of threads, but take into account that
25 is the general optimal number of threads, and overcoming have negative
effect due to context switching

Dand how do I have to do this.
DFor starting i have all emailaddresses in a Array.

The samples of using ThreadPool class are into MSDN

---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche




Michael Nemtsev schrieb:

Michael Nemtsev schrieb:

Hello Daniel ,


DI已经编写了一个应用程序,可以从数据库中获取电子邮件,并检查它是否是

Dcorrect电子邮件(连接到远程邮件服务器并检查

Dresponse)。

DI希望通过使用多个线程来提高性能。

Dcan我使用线程池吗?


你可以,但如果你有大量的长期任务,它可能不是1.1 fw的非常好的解决方案,因为TP''的数量那里的线程

受限于25个线程,如果你有多个长期运行的
操作,你会得到被阻塞的线程,等待25个线程中的一个完成

它的工作。


在2.0中你可以设置所需的线程数,但要考虑到

25是一般最佳数量由于上下文切换,eads和克服有负面的b $ b效果


Dand我该怎么做呢。

D For starting我有一个数组中的所有emailaddresses。


使用ThreadPool类的示例进入MSDN


---

WBR,

Michael Nemtsev ::博客: http:// spaces.live.com/laflour


有时一个人仍忠于某一事业只是因为它的对手没有

不再是平淡"。 (c)Friedrich Nietzsche
Hello Daniel,

DI have written a app that gets emails from a DB and checks if it''s a
Dcorrect email (connects to the remote mailserver and checks the
Dresponse).
DI would like to improve the performance with using multiple threads.
Dcan I use a threadpool for this?

You could, but it can be not the very good solution for the 1.1 fw if u have
a big number of long runned tasks, because the number of TP''s threads there
are limited by 25 thread, and in case if you have numbers of long-runned
operations u got the blocked threads which wait till one of 25 threads complete
its work.

In 2.0 u can set the desired number of threads, but take into account that
25 is the general optimal number of threads, and overcoming have negative
effect due to context switching

Dand how do I have to do this.
DFor starting i have all emailaddresses in a Array.

The samples of using ThreadPool class are into MSDN

---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche



感谢您的回答。我使用的是2.0 FW。所以它应该可以正常工作。

据我所知,在文档中,Pool正在使用max。 25线程

当时。有没有办法在标签中显示哪个线程

使用emailaddress?所以我可以看到这个过程。

我必须将不存在的电子邮件地址写回数据库。

当我从线程中执行此操作时,它将打开连接写回来

并关闭连接。对?但这可能会为数据库带来很多工作量。有没有办法打开锥形,然后写回所有地址然后关闭连接?
或者这不是那么重要吗?


Thanks for the answer. I use the 2.0 FW. So it should work fine.
As far as I could read in the docs, the Pool is using max. 25 threads
at the time. Is there a way to show in a label or so which thread is
working on with emailaddress? So I could have a view of the process.
I have to write back the not existing emailaddresses to the database.
when i do it from the thread, it will open the connection write it back
and close the connection. right? but this could produce a lot of work
for the db. is there a way to open the conecction ones and then write
back all addresses and then close the connection? or is this not so
important?


你好Daniel Daniel,
为了答案。我使用的是2.0 FW。所以它应该可以正常工作。

尽管我可以在文档中看到,但Pool正在使用max。 25个主题

比较时间。


是的,但这是每个处理器的每个进程,你可以改变它。


DIs有一种方式可以在一个标签中显示哪个线程是

使用emailaddress进行处理?


请参阅ThreadPool.GetAvailableThreads方法


所以我可以看到这个过程。

DI必须将不存在的电子邮件地址写回数据库。

当我从线程中执行此操作时,它将打开连接写入它

Dback

Dand关闭连接。对?但这可能会产生大量的工作

Dfor db。有没有办法打开锥形,然后写

Dback所有地址,然后关闭连接?或者这不是那么

Dimportant?


在MSSQL服务器中,您的数据库连接由defauilt汇集(在其他人中

DB他们不是),所以不介意


---

WBR,

Michael Nemtsev ::博客: http://spaces.live.com/laflour

有时一个人仍忠于某一事业,因为它的对手不会因为b $ b不再是平淡的。 (c)Friedrich Nietzsche
Hello Daniel,

DThanks for the answer. I use the 2.0 FW. So it should work fine.
DAs far as I could read in the docs, the Pool is using max. 25 threads
Dat the time.

Yep, but it''s per process per processor, and your can change it.

DIs there a way to show in a label or so which thread is
Dworking on with emailaddress?

see ThreadPool.GetAvailableThreads method

So I could have a view of the process.
DI have to write back the not existing emailaddresses to the database.
Dwhen i do it from the thread, it will open the connection write it
Dback
Dand close the connection. right? but this could produce a lot of work
Dfor the db. is there a way to open the conecction ones and then write
Dback all addresses and then close the connection? or is this not so
Dimportant?

In MSSQL server your DB connections are pooled by defauilt (in others
DB they are not), so don''t mind it

---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


这篇关于可以使用Threadpool的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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