Threading? VB

Posted on 2014-12-09
Last Modified: 2014-12-29
i am new to programming and have a question about threading.

I currently trying to add an sdk to an existing application and I have the ability to call a method when something happens in that application.  The problem is the application is performing a few actions and writing some records to SQL, but my sdk is trying to change those records.

My class is trying to delete the sql records and recreate the records, but before the application creates them after.  Someone told me I need to "thread"

Is there a way to call another method which will not be dependent on my SDK or the application?  I have tried both a thread and a threadpool, but I am just guessing.  The thread pool seems to work  but only for a few time and then i start getting error messages about time outs, etc.
Question by:red_75116
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 250 total points
ID: 40489420
What do you call a sdk?

A SDK is usually a Software Document Kit, something that you download from a vendor and contains documentation, tools and sample code to help you work with that vendor's software. You can download the SDK for Windows 8 as an example, to have stuff that is not in Visual Studio by default but can be useful to you if you work with Windows 8.

You are talking about a class of yours. Do you mean a dll in which you wrote your own class? This is not the same thing as a sdk.


You use threading when you need the application to perform 2 operations at the same time. As I understand it, your problem is exactly that 2 operations are working in parallel, so adding threads will just complicate things even more. Although you can control threads and pause one before the other one has finished, this is not something for a beginner. Using threads properly is one of the most complex thing you can do in programming. A lot of experienced programmers never do it because they find it too hard to control

What you might look for is to pause the operation that must complete first before running the operation that must execute later. There are different ways to do that, depending on what you are doing and using in the application.

If you are really using classes from a sdk, then you might read carefully the documentation for the classes and methods that it offers you. As an example, when you work in a Windows application, if you open a Form with the Show method, the code in the method that called Show continues running while the Form is building in the background. Both operations happen in parallel. But if you call the ShowDialog method instead, the calling method freezes for as long as the Form stays visible on the screen. This enables the application to pause while a user enters data, an then work with that data only after it has been completely entered. The difference is only to use ShowDialog instead of Show. Your sdk might have something like that.

If both operations are controlled through your own code, then you might want to add a pause in your application through the Sleep command. Launch your first operation, call Threading.Thread.Sleep(2000), then launch the second operation.

2000 means 2000 milliseconds (2 seconds). You will have to determine the best value to use there by trial and error. And if the background operation is one that could be performed on different computers, add some extra, because it might take longer to complete on a slower processor.

Yes, there is the work Thread in there, and I told you that threading is not for a beginner. That method is a special one in the Thread class. It does not start threads or control multiple threads (threads are useless if they are not multiple), it simply pause the current thread, that is the code that is running in the method in which it is called, which, if the specified delay is long enough, give time to the other threads to complete.

Accepted Solution

Ali HND earned 250 total points
ID: 40516039
For example:
Public Class Form1
    Private Tr1 As New Thread(AddressOf YourSub)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'Your Code        
    'Start Threading
            If Not Tr1.IsAlive Then
                Tr1 = New Threading.Thread(AddressOf YourSub)
                Tr1.IsBackground = True
            End If
    End Sub

    Sub YourSub()
            'Your Code
    End Sub

End Class

Open in new window


Author Closing Comment

ID: 40522443
Thanks, I was able to research a little more and get the new TASK feature to work.

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now