设为首页
加入收藏
站内地图
旧版入口
当前位置:首页 > 站长学院 > 网络编程 > ASP

xmlhttp让asp实现“多线程”

作者:佚名 出处:网络转载 时间:08-29 点击:

内容载入中...
 

  看了大白菜芯写的php实现多线程,一时间觉得有用,就改了个asp版的。。呵呵,这里感谢他的思路!(http://blog.csdn.net/wapweb/archive/2004/08/16/76319.aspx)

   1.原理实验

原理当然都一样,利用web服务器支持多线程,在同一页面里向服务器发多个http请求来完成我们的工作。更详细的分析,看大白菜芯写的吧。php里用Socket,asp当然用封装好了的xmlhttp了。

  还是先实验一下,在一个页面里同时写2个txt文件,比较写入时间的差异。代码如下:

<%

startime=timer()

''----------asp实现多线程----------''

 function runThread()

        dim Http

        set Http=Server.createobject("Msxml2.XMLHTTP")

        Http.open "GET","http://127.0.0.1/thread.asp?action=b",false

        Http.send()

 end function

 

 function a()

         dim Content,FilePath,MyFile

        Content=now()&chr(30)&timer()

              FilePath=server.MapPath("a.txt")

              Set fso = CreateObject("Scripting.FileSystemObject")

              Set MyFile = fso.CreateTextFile(FilePath, True)

              MyFile.Write(Content)

              MyFile.Close

 end function

 function b()

           dim Content,FilePath,MyFile

        Content=now()&chr(30)&timer()

              FilePath=server.MapPath("b.txt")

              Set fso = CreateObject("Scripting.FileSystemObject")

              Set MyFile = fso.CreateTextFile(FilePath, True)

              MyFile.Write(Content)

              MyFile.Close

 end function

if(Request.QueryString("action")="") then

        runThread()

        a()

收藏本文:
】【打印页面】【推荐给朋友】【关闭窗口

站长学院

推荐信息