Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / November 2006

Tip: Looking for answers? Try searching our database.

Multithreaded application, thread not quiting.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mitch Wardrop - 14 Nov 2006 16:42 GMT
ok here it goes I must be doing something way off but it makes sense to
me just not to VB.NET which would be a huge problem. Anyways I'll
explain what I am doing than give code examples. basicly I've declared a
thread in a module file where all my variables are declared for the
enitre application, than it calls the thread from the main form and runs
a sub routine located in a different class (I call it "work" class, this
is where all the code that actually does anything is stored), the thread
executes and begins dumping database data no problem, then when I open
up my disconnect dialogue window and click yes to disconnect and tell my
thread to quit it never quites in fact it just hangs the program, not
sure why. Anyways heres the code I am using if anyone can tell me what
is going on I would appreciate it.

file name : variables.vb

Module variable
    'Define Global Variables
    Public database As String = "WELLDAQ\DBINFO"
    Public dbusername As String = "******"
    Public dbpassword As String = "******"
    'job is declared by the work.activejob() routine called from the
start form
    Public job As String
    Public jobid As Integer
    Public dumplocation As String = "C:\uploader"
    Public jobtype As String
    Public server As String = "dkdserver.ath.cx"
    Public serverusername As String = "******"
    Public serverpassword As String = "******"
    Public disconnect As Boolean = False
    Public active As Boolean = False
    Public company As String
    Public dumpcount As Integer
    Public uploadcount As Integer
    Public connect = New Global.System.Threading.Thread(AddressOf
Work.Connect)
End Module

Filename : Main.vb

Imports System.Threading
Public Class Main
    Private Sub Connect_Button_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Connect_Button.Click
        variable.connect.Start()
    End Sub
End Class

Filename : disconnect.vb

Imports System.Threading
Public Class disconnect_form
    Private Sub Yes_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Yes.Click
        variable.connect.kill()
        Me.Close()
    End Sub
End Class
Robinson - 14 Nov 2006 16:57 GMT
> Imports System.Threading
> Public Class disconnect_form
[quoted text clipped - 4 lines]
>     End Sub
> End Class

Using Kill is very bad practice, especially if your thread is handling
unmanaged objects (or managed objects that are wrappers for unmanaged
objects), particularly any out of process COM objects - you can get all
kinds of strange and wonderful errors/exceptions/problems by doing this.
You should stop the thread by checking a bCancel flag inside the thread loop
and then invoking a "completed" delegate on the form.  Before setting the
bCancel flag in your Yes_Click handler, you should set a "bClosing" flag, so
you know to close the form when the thread invokes "completed".

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.