AU3假死问题:获取网页源代码期间短暂假死
Opt("GUIOnEventMode", 1)$Form1 = GUICreate("Form1", 361, 253, 192, 124)
GUISetOnEvent(-3, "Form1Close")
$Button1 = GUICtrlCreateButton("按钮", 86, 45, 75, 25)
GUICtrlSetOnEvent(-1, "Button1Click")
GUISetState(@SW_SHOW)
While 1
Sleep(100)
WEnd
Func Button1Click()
$a = TimerInit()
Local $Body
$oHTTP = ObjCreate("Msxml2.xmlhttp")
$oHTTP.Open('GET','http://www.autoitx.com/thread-30906-1-1.html&t=' & Random(0, 1),true);
$oHTTP.Send()
ToolTip(TimerDiff($a))
$Body = $oHTTP.responseBody
EndFunc
Func Form1Close()
Exit
EndFunc
当打开一个较大的网页时也会假死,用_INetGetSource 也会,假死的情况为拖动窗口拖不了,通讯完全阻断了 把http设置成异步,很大程度上已经避免了假死。要想窗体一点也不卡,只能用多线程了。 把http设置成异步,很大程度上已经避免了假死。要想窗体一点也不卡,只能用多线程了。
apprentice 发表于 2012-3-20 01:02 http://www.autoitx.com/images/common/back.gif
正在考虑要不要用多进程。。。 这个要考虑考虑了,也是代码的问题 这个问题是所有需要网络通信的程序都面临的,自己用的话就暂时隐藏Gui吧,否则就用多进程 本帖最后由 kxing 于 2012-3-20 09:45 编辑
Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Form1", 361, 253, 192, 124)
GUISetOnEvent(-3, "Form1Close")
$Button1 = GUICtrlCreateButton("按钮", 86, 45, 75, 25)
GUICtrlSetOnEvent(-1, "Button1Click")
GUISetState(@SW_SHOW)
While 1
Sleep(100)
WEnd
Func Button1Click()
$a = TimerInit()
Local $Body
$oHTTP = ObjCreate("Msxml2.xmlhttp")
$oHTTP.Open('GET','http://www.autoitx.com/thread-30906-1-1.html&t=' & Random(0, 1));
$oHTTP.Send()
ToolTip(TimerDiff($a))
$Body = $oHTTP.responseBody
while not $body
;这里可以换成guigetmsg模式,这样就能响应窗口事件了
$Body = $oHTTP.responseBody
if timerdiff($a)>=3000 then exitloop;设置超时时间
wend
EndFunc
Func Form1Close()
Exit
EndFunc
kxing 发表于 2012-3-20 09:44 http://www.autoitx.com/images/common/back.gif
很明显是不行,$oHTTP.Send()的时候已经阻断了所有通讯消息,你下面写什么都没用 还是用多进程吧 要不要考虑网络连通性问题。会不会更完美。O(∩_∩)O~,我不怎么懂这方面的内容。只是路过。 注册消息试试
#include <WindowsConstants.au3>
#include <GuiMenu.au3>
$Form1 = GUICreate("Form1", 361, 253, 192, 124)
$Button1 = GUICtrlCreateButton("按钮", 86, 45, 75, 25)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")
While 1
Switch GUIGetMsg()
Case $Button1
Button1Click()
EndSwitch
WEnd
Func Button1Click()
$a = TimerInit()
Local $Body
$oHTTP = ObjCreate("Msxml2.xmlhttp")
$oHTTP.Open('GET', 'http://www.autoitx.com/thread-30906-1-1.html&t=' & Random(0, 1), True);
$oHTTP.Send()
ToolTip(TimerDiff($a))
$Body = $oHTTP.responseBody
EndFunc ;==>Button1Click
Func WM_SYSCOMMAND($hWnd, $sMsg, $sWParam, $slParam)
Switch $sWParam
Case $SC_CLOSE ;结束程序
Exit
EndSwitch
EndFunc ;==>WM_SYSCOMMAND
页:
[1]