欢迎您来到GIS动力

加入收藏 免费注册 用户登陆 帮助中心
首页 新闻动态 技术专栏 银杏树下 学习考研 软件下载 求职招聘 许愿瓶 节日祝福 用户中心 精彩推荐 资源搜索 地图
专栏导航: AO开发 | SO开发 | ArcGIS桌面 | 超图桌面 | 开发语言 | 数据库 | WebGIS | 银杏文学 | 研究生考题 | FreeMap 谈天说地
   您现在位于: 首页技术专栏开发语言 → 正文
利用线程在C#中播放GIF
08-04-14 08:26:33 作者:Mike Gold 出处:Mike Gold

Figure 1 - Animated Gifs running in a ThreadPool

One of the nice features incorporated into the .NET framework is the ThreadPool class.  If you are not in the mood to manage your threads (determining when they sleep and when they wake up),  you can take advantage of this powerful class consisting of some easy to use static functions.  In this article we will discuss the use of the ThreadPool class in conjunction with the ImageAnimator class to run 3 animated gifs in separate threads.

The great thing about the ThreadPool class is you dont really have to deal with threads directly. There are two main methods used in this example from the ThreadPool class, each one is described below. 

ThreadPool Static Methods Description
RegisterWaitForSingleObject Used to trigger an Asynchronous callback with an event, if the event doesnt occur in the time out period, it triggers anyway.
QueueUserWorkItem Used to put a new worker thread in the thread pool along with an associated object.

Table 1 - ThreadPool class methods

ThreadPools have an added advantage over the thread class in that, not only do they allow you to create a thread, but also it lets you pass an object associated with the thread to the thread delegate.  I havent figured out how to do this with the Thread class yet.  Perhaps in the future, the .NET framework will be more accommodating with this task.

The object you pass into your delegate can be just about anything since it can box the instance of your class.  When you call QueueUserWorkItem, you pass in the delegate for your thread as the first parameter, and the associated object as your second parameter.

RegisterWaitForSingleObject has a different purpose.  It allows you to trigger a callback function with a WaitHandle or AutoResetEvent.  The WaitHandle lets you do things like trigger the callback

9 7 3 1 2 3 4 5 4 8 :

(本文已被浏览 次)
发布人:admin
推荐给好友:发送给好友
上篇新闻:
下篇新闻:
相关评论
发表我的评论
  • 尊重网上道德,遵守《全国人大常委会关于维护互联网安全的决定》及中华人民共和国其他各项有关法律法;
  • 本站有权保留或删除您发表的任何评论内容;
  •   相关文章  

    关于我们 友情链接 ┋ 与我在线 ┋ 管理 ┋ TOP
    网站当前版本:GisPower CMS V3.0
    『GIS 动力』- http://www.gispower.org/
    联系我们:webmaster#gispower.org
    Copyright (c) 2003-2007 GisPOwer.Org. All Rights Reserved.

                   滇ICP备05006901号