Foxtable(狐表)用户栏目专家坐堂 → [求助]网页异步函数未异步,望指点


  共有1631人关注过本帖树形打印复制链接

主题:[求助]网页异步函数未异步,望指点

帅哥哟,离线,有人找我吗?
浙江仔
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1316 积分:9484 威望:0 精华:1 注册:2010/7/21 14:20:00
[求助]网页异步函数未异步,望指点  发帖心情 Post By: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


 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107147 积分:544978 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2018/8/18 11:50:00 [只看该作者]

这里没有必要使用同步函数吧,都是调用外部接口的,不存在内部资源的争用问题。

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

 回到顶部
帅哥哟,离线,有人找我吗?
浙江仔
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1316 积分:9484 威望:0 精华:1 注册:2010/7/21 14:20:00
  发帖心情 Post By:2018/8/18 14:06:00 [只看该作者]

真的可以了,谢谢!
为什么反而加了SyncExecute就不行了呢?

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107147 积分:544978 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2018/8/18 14:17:00 [只看该作者]

参考;http://www.foxtable.com/mobilehelp/scr/3273.htm

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

 回到顶部