Results 1 to 4 of 4

Thread: [02/03] Threading and Web Exception

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    181

    [02/03] Threading and Web Exception

    Hey. I have a question on aborting a thread and error messages here. I have a thread that is used to do the following: creates a temporary directory on the c:\ drive, checks to see if a text file is available on my server, and downloads it if available. What I've created here is an updating system for my program basically. I have a STOP button that lets the user stop the process and close the updating forum. Here's some of my code:

    VB Code:
    1. Private Sub startUpdating()
    2.  
    3.         ButtonForceUpdate.Visible = False
    4.  
    5.         If findPaths() = True Then
    6.             If findDefinitions() = True Then
    7.                 If downloadDefinitions() = True Then
    8.                     startUIThread = True 'used to tell UI thread that it can check versions now
    9.                     'must now use timer to check instead of using delegate code
    10.                 Else
    11.                     Me.Close()
    12.                 End If
    13.             Else
    14.                 Me.Close()
    15.             End If
    16.         Else
    17.             Me.Close()
    18.         End If
    19.  
    20.     End Sub
    21.  
    22.     Private Function findPaths() 'finds temp download paths
    23.         LabelChecking.Text = "Creating Temporary Directories..."
    24.  
    25.         Try
    26.                 IO.Directory.CreateDirectory("C:\tempupdater")
    27.                 tempDIR = "C:\tempupdater"
    28.            
    29.             Return True
    30.         Catch ex As Exception
    31.             MsgBox(ex.Message)
    32.             Return False
    33.         End Try
    34.     End Function
    35.  
    36.     Private Function findDefinitions() 'find definitions on server
    37.         LabelChecking.Text = "Locating Definitions on Server..."
    38.         Try
    39.             wc.OpenRead("http://www.myserver.com/version.txt")
    40.             Return True
    41.  
    42.         Catch ex As Exception 'cant find definition
    43.             If MsgBox("The definition files couldn't be found on the server. Would you like to try again?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
    44.                 findDefinitions() 'try again if click yes
    45.             Else
    46.                 Return False
    47.             End If
    48.         End Try
    49.  
    50. Private Function downloadDefinitions()
    51.         LabelChecking.Text = "Downloading Definitions..."
    52.         Try
    53.             wc.DownloadFile("http://www.myserver.com/version.txt", tempDIR & "definitions.txt")
    54.             Return True
    55.         Catch ex As Exception
    56.             If MsgBox("An error occured while downloading definitions. The following error was returned:" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & " Would you like to try and download again?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
    57.                 downloadDefinitions()
    58.             Else
    59.                 Return False
    60.             End If
    61.  
    62.         End Try
    63.     End Function
    64.  
    65. Private Sub formUpdate_Closing(ByVal sender As Object, ByVal ByVale As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    66.         Try
    67.             IO.File.Delete(tempDIR & "definitions.txt")
    68.             IO.Directory.Delete(tempDIR, True)
    69.         Catch ex As Exception
    70.  
    71.         End Try
    72.  
    73.         startUpdatingThread.Abort()
    74.         Me.Dispose()
    75.         fu = Nothing
    76.     End Function

    ok so that's basically all my code that's in a thread. I apologize in advance, because I'm new to programming so it might not be correct. Ok the problem is that when the user wants to stop updating, then it will give me an error. For example if the user is currently in the stage for downloading the definitions, it will throw the exception there about not being able to download them. So it actually confuses the user because they clicked stop. How can I make it so that it will just stop with no errors and what not? Any ideas?

    Thanks
    John

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    181

    Re: [02/03] Threading and Web Exception

    anyone?

  3. #3
    Fanatic Member -TPM-'s Avatar
    Join Date
    Jul 2005
    Posts
    850

    Re: [02/03] Threading and Web Exception

    How are you cloasing the thread? Just thread.abourt?
    TPM

    Add yourself to the VBForums Frappr Map!!

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    181

    Re: [02/03] Threading and Web Exception

    yes like in the .closing method for the forum. Is it not good programming practice to abort a thread when it's not done or something? That's basicalyl what I'm trying to do. Just stop the thread when the forum is done and it should stop everything in the background; but I end up getting an exception in whichever method the thread is currently running.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width