以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]网页异步函数未异步,望指点  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=123584)

--  作者:浙江仔
--  发布时间:2018/8/18 11:42:00
--  [求助]网页异步函数未异步,望指点

有个网页涉及网页接口调用获取数据,我用异步函数,但是调用过程还是卡住其他网页进程(本机调试,同时打开2个网页),望指点一下:

 

httprequest代码:

      Case "refleshregInfo.htm"

          e.AsyncExecute = True

          Functions.AsyncExecute("Http_E_Reg_Result_by_ss",e)

 

网页获取数据函数

Http_E_Reg_Result_by_ss

 

Dim e As RequestEventArgs = args(0)

Dim ss As String = e.PlainText

Dim wb As new WeUI

Dim sec As String

Dim Values() As String

Values = ss.split("|")

ss=Values(0)

 

Dim jiekou As String =Values(1)

 

Dim json As String

Dim stt As Date = Date.Now

 

If ss>"" Then

    If jiekou="旧接口" Then

        json=Functions.SyncExecute("ReturnEntInfo",ss)

    End If

End If

。。。。。。

 

Dim htm As String = wb.Build()

Dim jx As new JObject

 

\'由于wb.Build()生成的是完整的网页,下面通过标签查询只取表格的html代码

Dim idx1 As Integer = htm.IndexOf("<body")

Dim idx2 As Integer = htm.IndexOf("</body>")

If idx1 >= 0 And idx2 >= 0 Then

    jx("foxhtm") = CStr(htm.SubString(idx1,idx2 + 8 - idx1)) \'只取表格的html代码

    e.WriteString(jx.ToString)

End If

e.Handled = True

 

 

函数ReturnEntInfo

Dim entname As String=args(0)

If entname.length>=11 Then

    entname=entname.SubString(0,11)

End If

 

 

Dim st As New Date(1970,1,1,8,0,0)

Dim timestamp As String = CInt((Date.Now - st).TotalSeconds()) .Tostring

Dim stt As Date = Date.Now

 

Dim appKey As String=密钥

Dim appcode As String =密钥

 

Dim RequestSecret As String=Functions.SyncExecute("GetRequestSecret")

 

Dim sign As String=MD5(appKey & RequestSecret & timestamp,32)

Dim url As String="http://网址:8088/interface/public/risen-api/bussinessLinces.action?C_REGNO="+ entname +"&appKey=" + appKey +"&sign=" +sign +"&requestTime="+ timestamp     

 

Dim hc As New HttpClient(url)

Dim ret As String = hc.GetData()

If ret = "" Then \'如果失败,再尝试一次

    hc.GetData()

End If

If ret <>"" Then

    Dim jo As JObject = Jobject.Parse(ret)

    If jo("code")="00" Then

        Return jo.ToString

    End If

End If

 

函数

GetRequestSecret

 

Dim appKey As String=密钥

Dim appcode As String =密钥

 

Dim refreshSecret As String =Functions.SyncExecute("GetRefreshSecret")

Dim st As New Date(1970,1,1,8,0,0)

Dim timestamp As String = CInt((Date.Now - st).TotalSeconds()) .Tostring

 

 

\'以下为新取值

Dim stt As Date = Date.Now

Dim sign2 As String =MD5(appKey & refreshSecret & timestamp ,32)

Dim url As String ="http://网址:8088/interface/public/risen-inte/reTokenBySec.action?appKey=" + appKey +"&sign=" +sign2 +"&requestTime="+ timestamp

 

Dim hc As New HttpClient(url)

hc.TimeOut = 6

Dim ret As String = hc.GetData()

If ret = "" Then \'如果失败,再尝试一次

    hc.TimeOut = 10

    hc.GetData()

End If

 

Dim jt As JObject = Jobject.Parse(ret)

If jt("code")="00" Then

    Dim RequestSecret As String =jt("datas")("requestSecret")

    Return RequestSecret

Else

    Return ""

End If


--  作者:有点蓝
--  发布时间:2018/8/18 11:50:00
--  
这里没有必要使用同步函数吧,都是调用外部接口的,不存在内部资源的争用问题。

SyncExecute全部改为普通方式调用即可

--  作者:浙江仔
--  发布时间:2018/8/18 14:06:00
--  
真的可以了,谢谢!
为什么反而加了SyncExecute就不行了呢?

--  作者:有点蓝
--  发布时间:2018/8/18 14:17:00
--  
参考;http://www.foxtable.com/mobilehelp/scr/3273.htm

同步简单理解就要等待的意思,等别人做完事