I am using httpsecuresocket and subclassing it to use page received.
I need to get an order list then iterate through the ids and get the order detail
I have been using page received to trigger app.cmd_complete=true and using a loop to wait
[quote=230261:@Tim Kearns]I am using httpsecuresocket and subclassing it to use page received.
I need to get an order list then iterate through the ids and get the order detail
I have been using page received to trigger app.cmd_complete=true and using a loop to wait
While app.cmd_complete=false
app.DoEvents
wend
I keep reading how I should not use DoEvents.
What is the preferred method?
TIA
Tim[/quote]
You should not use a tight loop to monitor Page Received, but rather what you need to do in a timer triggered from PageReceived.
The need to doEvents stems from the use of a tight loop that otherwise would freeze the current thread.
If you absolutely want to keep you polling scheme, then put your tight loop inside a thread. It won’t freeze the app and you will not need App.DoEvents.
I catch everything with PageReceived’s coming from many async Http requests at the same time.
Why can’t you let the PageReceived not call the appropriate function or just handle it?
With some sites such as CNN.com page received can fire several times in a row. So a timer will ensure catching the last occurrence. It is also a good idea not to do too many things in PageReceived to avoid holding the event while a new page has been received, which may lead to miss it. This is valid for most such events such as DataAvailable.
I don’t know what “the” preferred method is, but “my” method is:
If i encounter a situation in which a process can block my UI, i use Threads and their Prioritys to keep my UI responsive. As soon as a Thread ended which needs to update the UI, i start a Timer which updates the UI.
I start a Thread
When the Thread ends, it starts a Timer which updated the UI
The Timer starts the next Thread if needed
and so on…
So in your case maybe, start a Thread from the PageReceived Event. This Thread then starts a Timer as soon as all calculations have been done, to update the UI. If there’s a possibility that PageReceived could fire again before the Thread or Timer has finished it’s work, you could work with Thread Arrays. The Timer just needs to be aware of it.
But occasionally I will get a 502 back from the server when looping through the orders to get the order detail.
(api timeout / limit reached perhaps)?
What is the best way handle the error.
I am just trying to create jsonitems for the orders and the orderdetails
[code] dim orderJsonitem As JSONItem
dim orderid As String
dim orders as JSONItem
if IsNull(app.OrderDetailsList) then
app.OrderDetailsList=new JSONItem
end if
Dim curOrders as JSONItem
Select Case app.cmd
case “getOrders”
dim orderContent as new JSONItem(content)
curOrders=orderContent
app.OrderList=Curorders
orders=app.OrderList.Value(“orders”)
orderJsonitem=Orders.child(curLoop)
orderid=orderJsonitem.Value(“number”)
LoopCount=orders.Count -1
if curLoop<loopCount then
url="http://www.staging.com/api/orders/" + orderid
app.cmd="getOrdersDetail"
self.SendRequest("Get",url)
end if
case “getOrdersDetail”
curLoop=curLoop +1
dim ordersDetail as new JSONItem(content)
app.OrderDetailsList.Append(ordersDetail)
orders=app.OrderList.Value("orders")
orderJsonitem=Orders.child(curLoop)
orderid=orderJsonitem.Value("number")
if curLoop<loopCount then
url="http://www.staging.com/api/orders/" + orderid
app.cmd="getOrdersDetail"
self.SendRequest("Get",url)
else
Break
end if