Go Premium for a chance to win a PS4. Enter to Win


Threading? VB

Posted on 2014-12-09
Medium Priority
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 1000 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 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

773 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