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!!!
Visual Basic.NET

Avatar of undefined
Last Comment
slightlyoff

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Jacques Bourgeois (James Burger)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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!
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck