Results 1 to 4 of 4

Thread: *.gif image in picturebox "freezes" when searching for file on server.

  1. #1
    .NET Framework
    .NET 4.5
    Join Date
    Nov 2018
    Posts
    6
    Reputation
    0

    *.gif image in picturebox "freezes" when searching for file on server.

    Hey People,

    New question.

    I have a verification screen where all the buttons pressed-information is stored in text-boxes.
    Once pressed the "save to database" button, he's looking up on a server in a folder if a particular excel file with current year and week-number exist.
    2 options:
    1. The file exist: write the information from the textboxes in the last row of the existing excel file.
    2. The file doesn't exist: create a file and add information from textboxes to the first free line available.

    No problems with that.

    The problem is because of the wireless internet connection searching does take a bit longer.

    So i'm adding a Picturebox with a gif image that would show a please wait animation.
    I call the gif animation to hide when the verification screen opens.
    I call the gif animation to show when the "save to database" button is pressed.

    So it hangs when looking on the server for the file-search.

    I thought, let me introduce a timer with 2 sec before looking on the server and see how that works out. Unfortunately when the 2 seconds are out and the code starts, the gif file stops again untill the code stops.

    Any help?

    This is the code:

    Code:
    Public Class VerificationScreen
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            PictureBox1.Show()
            Timer1.Interval = 2000 'sets the timer's tick interval to 2 sec
            Timer1.Enabled = True 'the timer is disabled on form load so you have to enable it
        End Sub
        Private Sub Timer1_tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Timer1.Enabled = False
            Dim TargetWorkbook As Excel.Workbook = Nothing
            Dim SourceWorkbook As Excel.Workbook = Nothing
            Dim Target_Path As String
            Dim strFile As String
            strFile = TextBox6.Text
            If Len(strFile) = 0 Then Exit Sub
    
    
            '''''Assign the Workbook File Name along with its Path
            '''''Change path of the Target File name
            Target_Path = "S:\Quality\~SIPSTATION~\BACKUP FILES\PC1\" & Date.Today.Year & strFile & ".xlsx"
            If Len(Dir(Target_Path)) = 0 Then
                MsgBox("File does not exist, creating new file...")
                Call NewWb()
            Else
                Call AdjustWb()
            End If
        End Sub

  2. #2
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    14,007
    Reputation
    1731
    If you're doing other work on the UI thread, the UI thread cannot animate the image. You should always be doing long-running tasks in the background so the UI thread can look after the UI.

  3. #3
    .NET Framework
    .NET 4.5
    Join Date
    Nov 2018
    Posts
    6
    Reputation
    0
    The problem I'm dealing with is that I can't close the main form from another thread while using the backgroundworker method

  4. #4
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    14,007
    Reputation
    1731
    So do it on the UI thread. The BackgroundWorker has a ReportProgress method that can be called in the DoWork event handler to raise the ProgressChanged event on the UI thread. Any code you put in the ProgressChanged event handler is executed on the UI thread. Despite the name, you can use that method and that event for doing anything you want. If the only thing you want to do is close the form then just call ReportProgress and pass zero as the progress value, then call Close in the ReportProgress event handler. If you want to be able to do different things in the ReportProgress event handler, pass a second parameter to ReportProgress that identifies what you want to do. You might define an Enum for that. You can then test that value in the ReportProgress event handler to decide what to do. You can check out my own examples here:

    http://www.vbforums.com/showthread.php?471889

    Post #4 in that thread uses the UserState to pass data from the DoWork event handler to the ProgressChanged event handler. The data is different in that case but you can pass whatever you want via that parameter.

Similar Threads

  1. Replies: 5
    Last Post: 05-01-2008, 5:06 PM
  2. Is there a "cleaner" way of searching data?
    By Arg81 in forum Windows Forms
    Replies: 1
    Last Post: 10-25-2007, 6:24 AM
  3. Replies: 0
    Last Post: 03-30-2006, 12:34 PM
  4. "project" -> "add windows form" -> "data form wizard"question
    By ssfftt in forum Database General Discussion
    Replies: 0
    Last Post: 11-16-2005, 6:40 AM
  5. PictureBox2.ImageLocation = "en.gif"
    By cablehead in forum Graphics/GDI+
    Replies: 7
    Last Post: 09-23-2005, 1:24 PM

Bookmarks

Posting Permissions

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