What should use instead of DoEvents

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=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.

Or run the code in PageReceived directly?

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 cannot think of a way that would ever happen. Maybe with a socket- or shell- DataAvailable event but that shouldn’t happen on a PageReceived.

I assume you create different instances per request right? I don’t even know of another way. How would that hold previous events?

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.

  1. I start a Thread
  2. When the Thread ends, it starts a Timer which updated the UI
  3. The Timer starts the next Thread if needed
  4. 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.

It is subclassed socket. Chances are it has been dragged onto the window, and not instanciated.

Ok I switched everything to run from pageReceived

it seems to work ok

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

End Select
[/code]

PageReceived gives you HTTPStatus as Integer.