Thread not starting sub VB.NET

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.


LVL 2
Benji_Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Carl TawnSystems and Integration DeveloperCommented:
You seem to have forgotten the "attached code" step of your question :)
0
 
Benji_Author Commented:
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
CodeCruiserCommented:
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
 
Erick37Commented:
>>This was previously working perfectly, and now it has completely stopped.

What has changed since it was last working?
0
 
OrcbighterCommented:
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
 
Benji_Author Commented:
The boolean variables are true, even if I put a message box in that subroutine with nothing else, it still does not execute.
0
 
Benji_Author Commented:
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
 
Benji_Author Commented:
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
 
CodeCruiserCommented:
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
 
Benji_Author Commented:
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
 
CodeCruiserCommented:
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
 
Benji_Author Commented:
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
 
CodeCruiserCommented:
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
 
Benji_Author Commented:
I changed it from a console application to a GUI application. No other subs are running at the thread execution time.
0
 
CodeCruiserCommented:
But the main thread is obviously running. Do you interact with the UI in any of the threads?
0
 
Benji_Author Commented:
Yes, there is one UI interaction which is posting to a listbox.
0
 
CodeCruiserCommented:
Comment that out and see what happens. You can not interact (directly) with UI from a thread.
0
 
Benji_Author Commented:
It is working. Thanks for that information. Ok, so is there a way to interface with the UI via proxy?
0
 
Benji_Author Commented:
Solution provided worked.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.