VB.NET System.Threading.Sleep

slightlyoff
slightlyoff used Ask the Experts™
on
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!!!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2015
Commented:
I would really do not thing that a Sleep could cause a problem, since you are simply delaying a write.

But you can never be sure of anything unless you have tested it. Since it will be working on an important database, it needs to be tested not matter what before being put into production.

I have never worked with QuickBooks, but all the accounting programs I have worked with in the past enabled me to make a copy of my data files, and open that copy instead of the main one. A simple backup that is restored somewhere else might do it. Why not make a copy of your QuickBooks files and perform your tests on that copy?

Author

Commented:
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!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial