Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
...works fine for my purposes for checking for a new file version, but it still locks up the UI when it is connecting to the server. Once it connects, the UI unlocks but I'd like to eliminate the brief 3 second lag it causes.
Posted

The user clicks on a menuitem then this code executes:

 


   ''' <summary>
   ''' Gets the update information.
   ''' </summary>
   ''' <remarks></remarks>
   Friend Sub GetUpdate()

       If My.Computer.FileSystem.FileExists(MainForm.Path & "newVersion.txt") Then
           My.Computer.FileSystem.DeleteFile(MainForm.Path & "newVersion.txt")
       End If

       Dim baseUri As New Uri("http://www.blisspointranch.com/")
       Dim basePath As New Uri(baseUri, "programs/charactersheet/")
       Dim filePath As New Uri(basePath, "version.txt")

       'Disable menu item.
       MainForm.menuitemUpdate.Text = "Checking for Updates..."
       MainForm.menuitemUpdate.Enabled = False

       'Try to download file. If can't: Display returned server error, re-enable menus, exit subroutine.
       Try
           MainForm.webclient.DownloadFileAsync(filePath, MainForm.Path & "newVersion.txt")
       Catch ex As UriFormatException
           MessageBox.Show("Could not check for new version, server reported an error: " & vbCrLf & _
                                      ex.Message & vbCrLf & _
                                      "If this problem persists contact the program vender for support.", _
                                      My.Application.Info.Title, _
                                      MessageBoxButtons.OK, _
                                      MessageBoxIcon.Error)
       Catch ex As WebException
           MessageBox.Show("Could not check for new version, server reported an error: " & vbCrLf & _
                                     ex.Message & vbCrLf & _
                                     "If this problem persists contact the program vender for support.", _
                                      My.Application.Info.Title, _
                                      MessageBoxButtons.OK, _
                                      MessageBoxIcon.Error)
       Catch ex As InvalidOperationException
           MessageBox.Show("Could not check for new version, server reported an error: " & vbCrLf & _
                                     ex.Message & vbCrLf & _
                                    "If this problem persists contact the program vender for support.", _
                                    My.Application.Info.Title, _
                                    MessageBoxButtons.OK, _
                                    MessageBoxIcon.Error)
       Finally
           MainForm.menuitemUpdate.Text = "Check for Updates..."
           MainForm.menuitemUpdate.Enabled = True
       End Try

   End Sub

Posted

You may try something ~ like this: [you'll need to use threads]

 

using System.Threading;
// add top
public delegate void CheckForUpdateCallback();
private Thread updateChecker;

// menu_click
updateChecker = new System.Threading.Thread(GetUpdate);
updateChecker.Start();

// add to end of GetUpdate
this.Invoke(new CheckForUpdateCallback(Finished), new object[] {  });

// create new method for "finished"
private void Finished()
{
MessageBox.Show("Finished - " + DateTime.Now.ToString());
}

 

 

This should cause the entire operation to run Asnyc from the UI.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...