Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

730 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