Solved

Threading? VB

Posted on 2014-12-09
3
116 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
[X]
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
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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 (http://www.ecb.europa.eu/stats/exch…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

734 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