CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

线程池中线程完成后如何主动告知主线程

楼主jiaxunzaixian(逐日)2004-12-02 01:11:35 在 .NET技术 / C# 提问

1:线程池中线程完成后如何主动告知主线程,可以使线程池中线程在完成时候引发事件然后交与主线程处理吗?或者有别的方法。  
  2:将包涵线程池的类编译成DLL后在ASP.NET中调用会出现什么情况?是不是所有用户调用生成的线程都在一个线程池中,那么进行线程池管理的时候会混淆不同用户生成的线程。 问题点数:0、回复次数:11Top

1 楼usepc(usepc)回复于 2004-12-02 02:09:16 得分 0

哈哈,我已在QQ上跟你说了。Top

2 楼jiaxunzaixian(逐日)回复于 2004-12-02 02:12:27 得分 0

熟人开玩笑,本人并不了解,请高手现身.Top

3 楼usepc(usepc)回复于 2004-12-02 02:16:40 得分 0

http://dev.csdn.net/article/18/18280.shtmTop

4 楼saucer(思归)回复于 2004-12-02 02:52:35 得分 0

use   an   event,   like   AutoResetEvent     or   ManualResetEvent,   see  
   
  Synchronizing   Data   for   Multithreading  
  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconmanagedthreadingsupport.asp  
   
  Practical   Multithreading   for   Client   Apps  
  http://msdn.microsoft.com/msdnmag/issues/04/01/NET/default.aspxTop

5 楼DotNetFreak()回复于 2004-12-02 05:53:18 得分 0

1:线程池中线程完成后如何主动告知主线程,可以使线程池中线程在完成时候引发事件然后交与主线程处理吗?或者有别的方法。  
   
  最简单的就是象楼上所说的用AutoResetEvent,  
  但缺陷在于不能用call   back   返回数据  
  只能通过公共变量来传递数据  
  更灵活的方法是用   delegate.BeginInvoke(   AsyncCallback   ...)  
  但这就不是用thread   pool   里面的thread   了  
   
  2:将包涵线程池的类编译成DLL后在ASP.NET中调用会出现什么情况?是不是所有用户调用生成的线程都在一个线程池中,那么进行线程池管理的时候会混淆不同用户生成的线程。  
   
  是的,因为都在同一个asp.net   的process   里面  
  thread   pool   本身不会混淆哪个是哪个  
  至于你的数据就要看你自己的code   怎么处理了Top

6 楼DotNetFreak()回复于 2004-12-02 05:56:32 得分 0

对不起,我上面说错了一点,你用BeginInvoke   的时候其实也是在用thread   pool   里面的thread   来完成任务,不过是.net   framework   代你用了,不需要你自己QueueUserWorkItemTop

7 楼xiaoslong(龙哥)回复于 2004-12-03 15:34:22 得分 0

帮你顶一下Top

8 楼programmer11(程序员)回复于 2004-12-03 15:46:14 得分 0

跟楼主借个光学学Top

9 楼nga96(因为我笨,所以努力。陈勇华)回复于 2004-12-03 21:17:16 得分 0

delegateTop

10 楼zhongtr(种田人)回复于 2004-12-09 19:02:28 得分 0

gzTop

11 楼OneDotRed(武装到眼神)回复于 2004-12-31 14:20:05 得分 0

The   CLR   assigns   the   threads   from   the   thread   pool   to   the   tasks   and   releases   them   to   the   pool   once   the   task   is   completed.   There   is   no   direct   way   to   cancel   a   task   once   it   has   been   added   to   the   queue.  
   
  Thread   pooling   is   an   effective   solution   for   situations   where   tasks   are   short   lived,   as   in   the   case   of   a   web   server   satisfying   the   client   requests   for   a   particular   file.   A   thread   pool   should   not   be   used   for   extensive   or   long   tasks.  
   
  Thread   pooling   is   a   technique   to   employ   threads   in   a   cost-efficient   manner,   where   cost   efficiency   is   defined   in   terms   of   quantity   and   startup   overhead.   Care   should   be   exercised   to   determine   the   utilization   of   threads   in   the   pool.   The   size   of   the   thread   pool   should   be   fixed   accordingly.  
   
  All   the   threads   in   the   thread   pool   are   in   multithreaded   apartments.   If   we   want   to   place   our   threads   in   single-thread   apartments   then   a   thread   pool   is   not   the   way   to   go.  
   
  If   we   need   to   identify   the   thread   and   perform   various   operations,   such   as   starting   it,   suspending   it,   and   aborting   it,   then   thread   pooling   is   not   the   way   of   doing   it.  
   
  Also,   it   is   not   possible   to   set   priorities   for   tasks   employing   thread   pooling.  
   
  There   can   be   only   one   thread   pool   associated   with   any   given   Application   Domain.  
   
  If   the   task   assigned   to   a   thread   in   the   thread   pool   becomes   locked,   then   the   thread   is   never   released   back   to   the   pool   for   reuse.   These   kinds   of   situations   can   be   avoided   by   employing   effective   programmatic   skills.  
  ------------------------------------------------------  
  所以只有在一个线程结束时考虑使用delegate通知主线程  
  Top

相关问题

  • java 线程,对当前线程(非主线程)调用sleep,为什么主线程(窗口)也没反应了
  • GUI主线程waitforsingleobject的问题?
  • 主线程不能等待吗?
  • 为何向主线程发送一条消息,主线程却没有响应。
  • 在主线程中安全终止工作线程的方法?
  • 怎样在主线程中得到线程终止事件???
  • 困惑:子线程如何使用主线程的变量?
  • 子线程里如何调用主线程中的方法?
  • 辅助线程与主线程的通信问题
  • 在其他线程中向主线程发消息的问题

关键词

  • asp.net
  • 线程
  • 用户
  • 数据
  • asp
  • 主线程
  • 调用
  • 主动告知
  • 完成
  • 生成

得分解答快速导航

  • 帖主:jiaxunzaixian

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo