异步编程 [英] Asynchronous Programming

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

问题描述

我正在尝试确定是否需要使我的应用程序成为多线程,或者如果可以通过异步编程完成,则需要
。我意识到asynch调用

确实在后台创建了一个新线程,但是当它们回来时,它们会返回启动它们的线程,这是正确的吗?如果我去
多线程,那么我只需要为每个新的

连接生成一个新线程,对吧?


我在这里做的是创建一个通过TCP接受连接的服务,

做一些事情,然后返回一个响应。我最好的选择是

asych还是多线程?任何一个或两个上的任何文章都会很多赞赏。


谢谢,

史蒂夫

解决方案

" Steve - DND" <史蒂夫@ digitalnothing.com>!在消息中写道

新闻:O6 **************** @ TK2MSFTNGP09.phx.gbl ...

我''我试图确定我是否需要使我的应用程序多线程,
或是否可以使用异步编程完成。我意识到asynch
调用会在后台创建一个新线程,但当它们返回时,它们会返回启动它们的线程,这是正确的吗?如果我去多线程,那么我只需要为每个新的
连接生成一个新线程,对吧?

我在这里做的是提供服务通过TCP接受连接,
执行一些操作,然后返回响应。我最好的选择是去asych还是多线程?任何一篇或两篇文章都会受到很多赞赏。

谢谢,
史蒂夫




这里''我最喜欢的关于.NET中线程的文档:

http://www.eps-software.com/download..._threading.pdf

Erik


< blockquote>" Steve - DND" <史蒂夫@ digitalnothing.com>!写在

新闻:O6 ************** @ TK2MSFTNGP09.phx.gbl:

我正在试图确定是否我需要使我的应用程序具有多线程,
或者是否可以通过异步编程完成。我意识到asynch调用会在后台创建一个新线程,但是当它们返回时,它们会返回启动它们的线程,这是正确的吗?如果我去多线程,那么我只需要为每个新连接生成一个新线程,对吧?


我的建议是,除非它只是一个孤立的任务 - 例如单个文件读取

或其他,将其线程化。你的代码会更清晰。

我在这里做的是创建一个通过TCP接受连接的服务,做一些事情,然后返回一个响应。我最好的选择是asych还是多线程?任何一篇或两篇文章都会非常感激。




多线程。你的代码会更干净,更易于维护。

-

Chad Z. Hower(又名Kudzu) - http://www.hower.org/Kudzu/

编程是一种打架的艺术形式返回"




" Erik Frey" < ER ******* @ hotmail.com>在消息中写道

新闻:例如************** @ TK2MSFTNGP11.phx.gbl ...

" Steve - DND" ; <史蒂夫@ digitalnothing.com>!在消息中写道
新闻:O6 **************** @ TK2MSFTNGP09.phx.gbl ...

我正在努力确定如果我需要使我的应用程序多线程,


,如果它可以通过异步编程完成。我意识到asynch


调用

在后台创建一个新线程,但是当它们回来时,它们会返回启动它们的线程,是那是对的吗?如果我去多线程,那么我只需要为每个新的
连接生成一个新线程,对吧?

我在这里做的是提供服务通过
TCP接受连接,做一些事情,然后返回一个响应。我最好的选择是去asych还是多线程?任何一篇或两篇文章都会受到很多赞赏。

谢谢,
史蒂夫



这里是我最喜欢的文件.NET中的线程化:

http:/ /www.eps-software.com/download..._threading.pdf




我有一个问题是可扩展性。我一直在阅读

,多线程方法可能不一定能很好地扩展。在切换开始杀死应用程序之前,有多少

个线程太多了?我将

在峰值时可能有大约50-75(可能高达100)并发连接

次。从我所看到的,听起来这将是太多的线程

来创建。


I''m trying to determine if I need to make my application multi-threaded, or
if it can be done with asynchronous programming. I realize that asynch calls
do create a new thread in the background, but when they come back, they
return to the thread that launched them, is that correct? If I go
multi-threaded, then I just need to spawn a new thread for each new
connection, right?

What I''m doing here is making a service that accepts connections via TCP,
does some stuff, and then returns a response. Would my best bet be to go
asych or multi-threaded? Any articles on either or both would be much
appreciated.

Thanks,
Steve

解决方案

"Steve - DND" <steve!@!digitalnothing.com> wrote in message
news:O6****************@TK2MSFTNGP09.phx.gbl...

I''m trying to determine if I need to make my application multi-threaded, or if it can be done with asynchronous programming. I realize that asynch calls do create a new thread in the background, but when they come back, they
return to the thread that launched them, is that correct? If I go
multi-threaded, then I just need to spawn a new thread for each new
connection, right?

What I''m doing here is making a service that accepts connections via TCP,
does some stuff, and then returns a response. Would my best bet be to go
asych or multi-threaded? Any articles on either or both would be much
appreciated.

Thanks,
Steve



Here''s my favorite doc regarding threading in .NET:

http://www.eps-software.com/download..._threading.pdf

Erik


"Steve - DND" <steve!@!digitalnothing.com> wrote in
news:O6**************@TK2MSFTNGP09.phx.gbl:

I''m trying to determine if I need to make my application multi-threaded,
or if it can be done with asynchronous programming. I realize that
asynch calls do create a new thread in the background, but when they
come back, they return to the thread that launched them, is that
correct? If I go multi-threaded, then I just need to spawn a new thread
for each new connection, right?
My advice is unless its just one isolated task - such as a single file read
or other, thread it. Your code will be much cleaner.
What I''m doing here is making a service that accepts connections via
TCP, does some stuff, and then returns a response. Would my best bet be
to go asych or multi-threaded? Any articles on either or both would be
much appreciated.



Multi threaded. Your code will be much cleaner, and more maintainable.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"



"Erik Frey" <er*******@hotmail.com> wrote in message
news:eg**************@TK2MSFTNGP11.phx.gbl...

"Steve - DND" <steve!@!digitalnothing.com> wrote in message
news:O6****************@TK2MSFTNGP09.phx.gbl...

I''m trying to determine if I need to make my application multi-threaded,


or

if it can be done with asynchronous programming. I realize that asynch


calls

do create a new thread in the background, but when they come back, they
return to the thread that launched them, is that correct? If I go
multi-threaded, then I just need to spawn a new thread for each new
connection, right?

What I''m doing here is making a service that accepts connections via TCP, does some stuff, and then returns a response. Would my best bet be to go
asych or multi-threaded? Any articles on either or both would be much
appreciated.

Thanks,
Steve



Here''s my favorite doc regarding threading in .NET:

http://www.eps-software.com/download..._threading.pdf



One thing I have a question on is scalability performance. I keep reading
that a multi-threaded approach may not necessarily scale very well. How many
threads is too many before the switching starts to kill the app? I will
probably have about 50-75(possibly up to 100) concurrent connections at peak
times. From what I have read, it sounds like this would be too many threads
to create.


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

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