Solved

Thread not starting sub VB.NET

Posted on 2010-11-24
20
522 Views
Last Modified: 2012-05-10
Hello everyone. I am having yet another problem with VB.NET

I have a system that constantly pings a database for commands to process, this needs to be running constantly, until it is stopped by the user. The interface of the application needs to remain responsive when this is running though, so I decided to enclose the checking process in a thread. I am using the attached code. It seems the thread starts, as if I call .IsAlive from the startthread sub, it shows it as true, but nothing in the sub is being called.

This was previously working perfectly, and now it has completely stopped.

Any advice would be greatly appreciated, thanks.


0
Comment
Question by:Benji_
20 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34205236
You seem to have forgotten the "attached code" step of your question :)
0
 
LVL 2

Author Comment

by:Benji_
ID: 34205484
I attached it, oh well. Here it is:

    Sub startthread()
        threadJobPing = New Thread(New ThreadStart(AddressOf JobPing))
        threadJobPing.Start()
        Log("CORE: Loaded Checker thread. Testing...")
    End Sub

    Sub JobPing()
        'log jobs pings to file
        If threadJobPing.IsAlive = True Then
            Log("Checker Thread Test Complete: Online")
        End If
        Do While smcCheckJobs = True
            If smcIsConfigured = True Then
                Log("Checking for available jobs...")
                AvailableJobs()
                CommandCheck()
                Thread.Sleep(180)
            Else
                Log("SMC is not configured.")
            End If
        Loop
    End Sub

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34205594
You can simplify this

New Thread(New ThreadStart(AddressOf JobPing))


to

New Thread(AddressOf JobPing)


Is it not executing any code in the sub? May be the boolean in while loop is not true.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 32

Expert Comment

by:Erick37
ID: 34205739
>>This was previously working perfectly, and now it has completely stopped.

What has changed since it was last working?
0
 
LVL 9

Expert Comment

by:Orcbighter
ID: 34211981
Where are the boolean variables in your sub routine defined?
Are these variables existing outside your thread? If so, they must be global to be seen. What other peices of code touch these variables? How have you made them threadsafe and avoided race conditions?
Where is the Log method calling? Is it outside your thread? If so, how have you made it threadsafe?
0
 
LVL 2

Author Comment

by:Benji_
ID: 34212350
The boolean variables are true, even if I put a message box in that subroutine with nothing else, it still does not execute.
0
 
LVL 2

Author Comment

by:Benji_
ID: 34212387
I tell a lie actually, If i put a message box in the sub, it does actually run. But even though the variables contain the correct values, they are not running the contents of the loop.
0
 
LVL 2

Author Comment

by:Benji_
ID: 34212485
To further extend the information, when I call the sub manually it works, other than the fact the interface is non-responsive (Which is to be expected). It seems that anything other than a messagebox does not work in that sub when it is called by a thread.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34212555
I think the reason could be that you are calling other subs from that sub. What happens if you copy the code from one of the subs to this sub?
0
 
LVL 2

Author Comment

by:Benji_
ID: 34212621
That is interesting, that code runs. Why is this problem occurring then? It has never happened before and the permissions on the other subs have not changed.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34218311
I think its clear that the problem is in calling another sub from a thread. Would it be possible to keep all the code in 1 sub?
0
 
LVL 2

Author Comment

by:Benji_
ID: 34218350
This is not possible no, because this thread calls upon subs which are needed outside of the thread. I am just wondering as to why this is happening now, when it wasn't previously? Is there any more information I can provide to shed some light on the situation?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34218422
Set breakpoints and see whether then other subs are being called or not at all. If it was working previously then it stopped, what change had you made?
0
 
LVL 2

Author Comment

by:Benji_
ID: 34218847
I changed it from a console application to a GUI application. No other subs are running at the thread execution time.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34219252
But the main thread is obviously running. Do you interact with the UI in any of the threads?
0
 
LVL 2

Author Comment

by:Benji_
ID: 34229191
Yes, there is one UI interaction which is posting to a listbox.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34229196
Comment that out and see what happens. You can not interact (directly) with UI from a thread.
0
 
LVL 2

Author Comment

by:Benji_
ID: 34229240
It is working. Thanks for that information. Ok, so is there a way to interface with the UI via proxy?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 34229307
0
 
LVL 2

Author Closing Comment

by:Benji_
ID: 34231235
Solution provided worked.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb.net checkbox 7 47
How can my static class become undefined?? 8 49
Disable extension 8 38
ASP/VB email question 4 35
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

777 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