We help IT Professionals succeed at work.
Get Started

VB.NET System.Threading.Sleep

slightlyoff
slightlyoff asked
on
258 Views
Last Modified: 2014-05-02
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
Top Expert 2015
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE