Solved

Threading? VB

Posted on 2014-12-09
3
104 Views
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.
0
Comment
Question by:red_75116
3 Comments
 
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.
0
 
LVL 3

Accepted Solution

by:
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
                Tr1.Start()
            End If
    End Sub

    Sub YourSub()
            'Your Code
    End Sub

End Class

Open in new window

0
 

Author Closing Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

18 Experts available now in Live!

Get 1:1 Help Now