Link to home
Get AccessLog in
Avatar of slightlyoff
slightlyoff

asked on

VB.NET System.Threading.Sleep

I have a program that downloads orders into QuickBooks using QuickBooks SDK.
Every now and then, while updating a customer's information, I get an error saying that the Customer's ListID is currently in use.

Normally, the program just tries to run the update again.  After 8 times, it quits trying and skips the order.

I've found that a short delay will typically allow the Customer to be update.  For example, if I shut the program down after the 8 restarts, and reopen the program, the Customer updates with no issues.  

This happens inside of a class called CustomerPC, which is called by the Main form.  Here's the calls the Update sub to run again:

If Main.RestartX < numRestartTimes then  'numRestartTimes is a constant set to 8
  UpdateCustomer()
  Exit Sub
Else
  Main.RestartX = 0
  Main.ExitMe()
  Exit Sub
End if

Open in new window


I think the issue is that it takes only a second for it to retry 8 times, not enough time for the customer to be released from whatever process is using it.  So I was thinking of changing it to this:

If Main.RestartX < numRestartTimes then  'numRestartTimes is a constant set to 8
  System.Threading.Sleep(10000)  'force it to wait 10 seconds before trying again
  UpdateCustomer()
  Exit Sub
Else
  Main.RestartX = 0
  Main.ExitMe()
  Exit Sub
End if

Open in new window


Since this program is being used right now and testing it involves messing with orders and accounting software, I wanted to make sure that it behaves as I'm expecting.

Thank you for your help!!!
ASKER CERTIFIED SOLUTION
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
Avatar of slightlyoff
slightlyoff

ASKER

That's a good idea. I do have a  test environment - although the problem doesn't typically show up during testing - and if there's no problem, it will skip over this line of code.

The issue with this particular problem is there's no rhyme or reason to it, I know what the problem is doing - but I can't duplicate it on purpose.  I'll look for ways to test it though, I don't want any weird side effects.

Thank you for your help!