cugone Posted December 15, 2008 Posted December 15, 2008 ...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. Quote
Nate Bross Posted December 15, 2008 Posted December 15, 2008 Can you post the code that you are using? Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
cugone Posted December 16, 2008 Author Posted December 16, 2008 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 Quote
Nate Bross Posted December 16, 2008 Posted December 16, 2008 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. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.