|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Multithreaded application, thread not quiting.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 > Imports System.Threading Using Kill is very bad practice, especially if your thread is handling > 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 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".
Application performance decrease after deleting rows
Check for Duplicate Appointment Times Hiding Default Constructor in VB Express 2005 (Public Not Creatable in VB6) .NET Serialization Quest Sound with New System.Media.SoundPlayer() Directory.Getfiles search pattern New SQL Express 2005 ? Cannot open a database from a previous version of your application compare/check character against an array of chars - best practice? Help!! Dynamic Textbox, validation requiredFieldValidator |
|||||||||||||||||||||||