当前位置:首页 » 软件开发
开发技术指南» 文章正文
    引言: Timer [C#] MILY: 宋体; mso-bidi-f
 

 

 ·在.net中的线程处理(2)    »显示摘要«
    摘要:.net 框架提供了许多有助于您创建和管理多线程应用程序的对象。waithandle 对象可以帮助您响应其他线程执行的操作,尤其是在与非托管代码交互操作时。threadpool 为大多数任务提供最佳的基本线程创建和管理机制。monitor、mutex、interlocked 和 readerwriterlock 提供用于在较低级别上同步执行的机制。timer 是一种非常灵活的用来以特定时间间隔引发......
 ·使用.net访问internet(5)    »显示摘要«
    摘要:同步客户端套接字示例 下面的示例程序创建一个连接到服务器的客户端。该客户端是用同步套接字生成的,因此挂起客户端应用程序的执行,直到服务器返回响应为止。该应用程序将字符串发送到服务器,然后在控制台显示该服务器返回的字符串。 [c#]using system;using system.net;using system.net.sockets;using system.text; public cla......


在.NET中的线程处理(4)
timer  [c#]

使用 timer 类是非常简单的.需要创建一个 timer(通过将 timercallback 委托传递到回调方法).一个表示将被传递给回调的状态的对象.初始引发时间以及表示回调调用之间的时间段的时间.若要取消挂起的计时器,请调用 timer.dispose 函数. 【程序编程相关:使用反射实现根据名称动态创建窗体的几种方

计时器是使您能够指定要在指定时间调用的委托的轻量对象.线程池中的线程执行等待操作. 【推荐阅读:字符串根据多个字符进行分割的一种方法(使

下面的简单代码示例说明了 timer 的使用. 【扩展信息:正弦函数的绘制的一种方法。(坐标变换与放

注意 还有 system.windows.forms.timer 类.该类是基于操作系统计时器支持的,如果您没有在线程上发送消息,则计时器将不会出现.这就使得 system.threading.timer 在许多情况下更为有用.

[visual basic]

imports system

imports system.threading

imports microsoft.visualbasic

 

public class timertest

  

   public timerevent as manualresetevent

  

   public sub new()

      timerevent = new manualresetevent(false)

      dim timer as new timer(new timercallback(addressof me.timermethod), nothing, timespan.fromseconds(5), timespan.fromseconds(5))

      dim ticktimer as new timer(new timercallback(addressof me.tick), nothing, timespan.fromseconds(1), timespan.fromseconds(1))

   end sub new

  

   public sub timermethod(state as object)

      console.writeline(controlchars.cr + "the timer invoked this method.")

      timerevent.set()

   end sub timermethod

  

   public sub tick(state as object)

      console.write(".")

   end sub tick

  

   public shared sub main()

      dim test as new timertest()

      console.writeline("the timer has started and will count for five seconds.")

      test.timerevent.waitone()

      console.writeline("...and control returned to the primary thread.")

   end sub main

end class timertest

[c#]

using system;

using system.threading;

 

public class timertest{

  


...   下一页
 ·使用.net访问internet(2)    »显示摘要«
    摘要:实现异步请求 system.net 类使用 .net 框架的标准异步编程模型对 internet 资源进行异步访问。webrequest 类的 begingetresponse 和 endgetresponse 方法分别启动和完成对 internet 资源的异步请求。 注意 在异步回调方法中使用同步调用可能会导致严重的性能降低。通过 webrequest 及其子代实现的 internet 请求......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE