Threading, Async Not working, animated gif problems/

I have asked this question several times in different ways.  All I want to do is show an animated Gif while my datagrid is being filled.  

I have Tried:

1) Async call for the  fill process   ---- The image shows, datagrid filles.  After that the program is totally lock up
2) Async call for the  animated gif  process   ---- The image shows, datagrid filles.  After that the program is totally lock up
3) Thread for the fill Process
4) Thread for the animated gif  --- I get multiple scroll bars vertical and horizontal, looks like this


                    I I
                    I I
---------------
---------------       The inner to work, the outer 2 dont

5) show, unshow images and the datagrid.

The database I am hitting is over 500megs. roughly 300,000 records in each table, about 10 tables.  The queries though decrease that number significantly

My my rescent attempt was to: Before the fill, delete the bindings to the datagrid. Pause, Create Thread, And rebind the the datagrid.  This didnt work as well.

Here is some Code:  Please dont go by the unbind, pause, rebind.  I was just trying that out.  Like I said I think I have tried everything in the book, I need something not in the book, or if someones knows a fix.  The only other thing I can think is a thread.join but I dont think that will woork either.

   Dim workThread As New System.Threading.Thread(AddressOf dowork)

 Private Sub search_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles search_btn.Click
        search()
    End Sub

Public Sub search()
        Me.spinsdesc_parent.Text = " "
            Me.spinsdesc_parent.Text = " "
            ds2.Clear()
            ds3.Clear()

            On Error Resume Next
            al.Clear()
            torecipientstring = " "

            Dim cmdText As String
            Dim srchStr As String
            Dim filterStr As String
            Dim whereSet As Boolean = False


            ' Create the filter string based on the options choosen from the menu
            ' If ESP is choosen filter by +
            '
            filterStr = IIf(grp_ESP_mnu.Checked(), espStr, filterStr.Empty)
            '
            ' If SST is choosen filter by +
            '
            filterStr &= IIf(grp_SST_mnu.Checked(), IIf(filterStr.Equals(String.Empty), sstStr, "," & sstStr), filterStr.Empty)
            '
            ' If Physical is choosen filter by +
            '
            filterStr &= IIf(grp_Physical_mnu.Checked(), IIf(filterStr.Equals(String.Empty), phyStr, "," & phyStr), filterStr.Empty)
            '
            ' If Campus is choosen filter by +
            '
            filterStr &= IIf(grp_Campus_mnu.Checked(), IIf(filterStr.Equals(String.Empty), campusStr, "," & campusStr), filterStr.Empty)

            ' If 3rd party is choosen filter by 'UNDEF +

            filterStr &= IIf(grp_misc3rd_mnu.Checked(), IIf(filterStr.Equals(String.Empty), partyStr, "," & partyStr), filterStr.Empty)

            'Retrieve the original Query String
            cmdText = qryStr

            ' Append the search string entered in the search box to the query
            ' Search both the Vendor column and Description column
            '
            If Not (search_txt.Text.Equals(String.Empty)) Then
                whereSet = True
                srchStr = search_txt.Text + "*"
                cmdText &= " where ((T_PARTS.PART_NUM = '" & srchStr & "') OR (T_PARTS.TRDB_PN "
                '   cmdText &= " OR ((T_PARTS.TRDB_PN) " ' added

                'Check for a wildcard
                'If found use the like operator otherwise equals
                If ((srchStr.IndexOf("*") > 0) Or (srchStr.IndexOf("?") > 0) Or (srchStr.IndexOf("&") > 0)) Then
                    srchStr = srchStr.Replace("*", "%")
                    srchStr = srchStr.Replace("?", "%")
                    srchStr = srchStr.Replace("&", "%")

                    '  cmdText &= " Like '" & srchStr & "') OR ((T_PARTS.TRDB_DESC ) Like '" & srchStr & "'))"
                    cmdText &= " Like '" & srchStr & "') OR ((T_PARTS.DESC ) Like '" & srchStr & "'))"
                Else
                    ' cmdText &= " = '" & srchStr & "') OR (T_PARTS.TRDB_DESC = '" & srchStr & "'))"
                    cmdText &= " = '" & srchStr & "') OR (T_PARTS.DESC = '" & srchStr & "'))"
                End If
            End If

            ' Append the filter string
            If Not filterStr.Equals(String.Empty) Then

                If Not (search_txt.Text.Equals(String.Empty)) Then
                    cmdText &= " AND T_PARTS.PRODUCT_CODE IN (" & filterStr & ")"
                Else
                    cmdText &= " WHERE T_PARTS.PRODUCT_CODE IN (" & filterStr & ")"
                End If
            End If

            ' Set the SelectCommand to the newly constructed query
        Me.OleDbSelectCommand1.CommandText = cmdText

        If threadactive = True Then
            MessageBox.Show("Wait For Current Search To Finish", "Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        Else
            Me.DataGrid.DataSource = Nothing
           
            startdowork()

            Thread.Sleep(5)
             Me.DataGrid.DataSource = Me.DbDataSet
            Me.DataGrid.Refresh()
        End If
    End Sub


    Private Sub dowork()
        ShowImage()
        Me.DbDataSet.Clear()

        Me.OleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & DBNAME & ";Persist Security Info=False"
        Me.OleDbDataAdapter1.Fill(Me.DbDataSet)

         endwork()
    End Sub
   
    Private Sub startdowork()
        threadactive = True
        workThread.Start()
    End Sub
   
 Public Sub endwork()
        HideImage()
        threadactive = False
           End Sub

Public Sub ShowImage()
        PictureBox1.Show()
        Me.search_lbl.Show()
    End Sub
   
 Public Sub HideImage()
        PictureBox1.Hide()
        Me.search_lbl.Hide()
    End Sub
   




malanoisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

planoczCommented:
are you using windows.forms or asp.net?
0
malanoisAuthor Commented:
forms
0
planoczCommented:
here is some code that has and animated gif  on a form.
It might help in what you are looking for.

Imports System
Imports System.Drawing
Imports System.Windows.Forms
Public Class animateImage
    Inherits Form
    'Create a Bitmpap Object.
    Private animatedImage As New Bitmap("animSmile.gif") 'Sample file
    Private currentlyAnimating As Boolean = False
    'This method begins the animation.
    Public Sub AnimateImage()
        If Not currentlyAnimating Then
            'Begin the animation only once.
            ImageAnimator.Animate(animatedImage, New EventHandler(AddressOf Me.OnFrameChanged))
            currentlyAnimating = True
        End If
    End Sub
    Private Sub OnFrameChanged(ByVal o As Object, ByVal e As EventArgs)
        'Force a call to the Paint event handler.
        Me.Invalidate()
    End Sub
    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        'Begin the animation.
        AnimateImage()
        'Get the next frame ready for rendering.
        ImageAnimator.UpdateFrames()
        'Draw the next frame in the animation.
        e.Graphics.DrawImage(Me.animatedImage, New Point(0, 0))
    End Sub
    Public Shared Sub Main()
        Application.Run(New animateImage)
    End Sub
End Class

I think this is all the code.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

malanoisAuthor Commented:
2 problems
1) It pops up a blank form with the image on it.
2) It still hangs, (The animated gif only shows 1 bar)(the gif is a progress meter that just keeps looping)


This is what I have done:

   Me.OleDbSelectCommand1.CommandText = cmdText

        If threadactive = True Then
            MessageBox.Show("Wait For Current Search To Finish", "Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        Else
            Me.DbDataSet.Clear()

            Me.OleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=" & DBNAME & ";Persist Security Info=False"

            '    ShowImage()
            animate.Show() <---------------It didnt show until I put this in
            animate.Activate()

            Me.OleDbDataAdapter1.Fill(Me.DbDataSet)
            ' startdowork()
            animate.Hide()

            'HideImage()

           
        End If
    End Sub

On the class, I changed the filename and the location.


The image doesnt do anything during the fill, it just freezes
0
planoczCommented:
Have you tried adding a   Application.DoEvents()
0
planoczCommented:
Do you want to just show a progressbar loading in the background per say.
0
malanoisAuthor Commented:
Have tried application.doevents in many ways and different locations.

Yes, that is the main Idea, to show the user the search is being performed.  I have tried even a animated mouse and that hangs as well.

I have tried a Progress Bar, 0 -100, lopp to 0 when it reaches a 100, then hide the progress bar.

Any suggestion, I'm up for.
0
planoczCommented:
Here is a form that I use with timers  as I fill a dataset with 3 tables.

Public Class frmSplash
    Inherits System.Windows.Forms.Form
    Public Shared oform As frmMyMainForm    '<-----Main Form
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    Friend WithEvents StartTimer As System.Windows.Forms.Timer
    Friend WithEvents LinkLabel As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmSplash))
        Me.ProgressBar1 = New System.Windows.Forms.ProgressBar
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.StartTimer = New System.Windows.Forms.Timer(Me.components)
        Me.LinkLabel = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'ProgressBar1
        '
        Me.ProgressBar1.Location = New System.Drawing.Point(4, 208)
        Me.ProgressBar1.Name = "ProgressBar1"
        Me.ProgressBar1.Size = New System.Drawing.Size(88, 16)
        Me.ProgressBar1.TabIndex = 0
        '
        'Timer1
        '
        Me.Timer1.Interval = 300
        '
        'StartTimer
        '
        '
        'LinkLabel
        '
        Me.LinkLabel.BackColor = System.Drawing.Color.Transparent
        Me.LinkLabel.ForeColor = System.Drawing.Color.Black
        Me.LinkLabel.Location = New System.Drawing.Point(100, 208)
        Me.LinkLabel.Name = "LinkLabel"
        Me.LinkLabel.Size = New System.Drawing.Size(156, 16)
        Me.LinkLabel.TabIndex = 1
        Me.LinkLabel.Text = "Please Wait... Loading Tables"
        '
        'frmSplash
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.White
        Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
        Me.ClientSize = New System.Drawing.Size(252, 228)
        Me.ControlBox = False
        Me.Controls.Add(Me.LinkLabel)
        Me.Controls.Add(Me.ProgressBar1)
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmSplash"
        Me.Opacity = 0
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.TopMost = True
        Me.ResumeLayout(False)

    End Sub
#End Region
    Private Sub beginLoadingComponents()
        Me.LinkLabel.Text = "Please Wait... Loading Tables"
        oform = New frmMyMainForm
        Me.Timer1.Enabled = True
        Me.ProgressBar1.Visible = True
        Dim i As Short

        Try
            For i = 1 To 9
                Me.ProgressBar1.Value += i
            Next
            FillDataSet(Table.Tb0)   'Dataset Table =0
            For i = 1 To 8
                Me.ProgressBar1.Value += i
            Next
            FillDataSet(Table.Tb1)   'Dataset Table =1
            Me.ProgressBar1.Value += i
            FillDataSet(Table.Tb2)   'Dataset Join both tables Table =2
            Me.LinkLabel.Text = "Please Wait... Loading Tables"
            If Me.ProgressBar1.Value >= 90 Then
                Me.LinkLabel.Text = "Tables loaded"
                Timer1.Enabled = False
                Me.Visible = False
            End If
        Catch Exp As ArgumentException
            If ProgressBar1.Value > 100 Then
                ProgressBar1.Value = 100
            End If
            Cursor.Current = Cursors.Default
            Application.Exit()  '<--- exit
        End Try
        oform.ShowDialog()      '<--- show your main form
        Application.Exit()      '<--- exit
    End Sub
    Dim elapsed As Short = 0
    Private Sub StartTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartTimer.Tick
        elapsed += 1
        Me.Opacity = elapsed * 0.1
        If elapsed >= 10 Then
            Me.LinkLabel.Visible = True
            Me.StartTimer.Enabled = False
            Me.beginLoadingComponents()
        End If
    End Sub
    Private Sub frmSplash_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.StartTimer.Enabled = True
    End Sub
End Class

You will need to change the beginLoadingComponents procedure.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
planoczCommented:
and add or own background image to the form
0
malanoisAuthor Commented:
Thank You,
0
planoczCommented:
I had fun playing with that form myself.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.