No Progress showing during adapt.fill

Posted on 2004-10-25
Last Modified: 2010-04-23
I have read article after article.

All I want to do is show the user that a search is in progress.

Image = animated gif.

I have tried to create another form that pops up.  image locks up during the fill
I have tried to create a progress bar. Progress bar freezes during fill.
I have tried showing an image on the main form. Image locks up

I have tried threading.  I threaded the fill-- that created multiple scroll bars
I have tried threading the image. Image still locks up

I have read and tried asynch-- image locks up

I have tried hiding the datagrid and showing the image, after the fill i reverse them.  image locks up.

I have tried several different image files, including a 4k jpg that says SEARCHING, image didnt show.

I am runn vs.2003
1 gig ram

? any ideas?

The search that it is performing is running through 300,000 records.
Question by:malanois
    LVL 8

    Expert Comment

    did you make sure to add


    in your loop?


    Author Comment

    yes it is there

    Author Comment

    I have tried this post

    the image and search are WORKING, it works great.  Just to the point of doing something else.

    After the datagrid is filled the program locks up.  It seems like this is not clearing out the async call.  

    How can I end this Async call????? or stop the async call

    here is the code I am using.....

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

            Dim _asyncResult As IAsyncResult
            _asyncResult = Me.BeginProcess(5, New AsyncCallback(AddressOf Process_Complete), Nothing)
        End Sub
     Public Function BeginProcess(ByVal seconds As Integer, ByVal callback As AsyncCallback, ByVal asyncState As Object) As IAsyncResult

            Dim _processDelegate As New ProcessDelegate(AddressOf Process)
            Return _processDelegate.BeginInvoke(seconds, callback, asyncState)

        End Function

        Public Function EndProcess(ByVal ar As IAsyncResult) As Boolean
     Dim _processDelegate As ProcessDelegate = DirectCast(DirectCast(ar, System.Runtime.Remoting.Messaging.AsyncResult).AsyncDelegate, ProcessDelegate)
            Return _processDelegate.EndInvoke(ar)
        End Function
     Public Sub Process_Complete(ByVal ar As IAsyncResult)

            Dim bSuccess As Boolean = EndProcess(ar)

            Me.PictureBox1.Visible = False
            Me.search_lbl.Visible = False
            threadactive = False

            'RaiseEvent DoneProcessing()    <----------------  I think some code has to go in here to end the async
        End Sub

        ' Private Sub DoWork()
        Public Function Process(ByVal seconds As Integer) As Boolean
            If threadactive = True Then
                MessageBox.Show("Wait For Current Search To Finish", "Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                Exit Function
                search()   <---------- this is just my filtering process and getting the query together
                threadactive = True

                Me.PictureBox1.Visible = True
                Me.search_lbl.Visible = True   <<<<<<<<<<---------This is where i am hiding the datagrid and show the gif  it is
                Me.DataGrid.Hide() <<<<<<<<<<<<<<<<<                  It is working great

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

                '// Do your work here
            End If

        End Function

    Any thoughts???

    LVL 6

    Expert Comment

    I assume you're working with Windows Forms.

    I've tried this before but the difference is that I instantiated my data adapter from a class rather than from a drag and drop design time component as evidenced by the name of your variable: OleDbDataAdapter1.

    I was also working with the datagrid so I used the technique described in this article:;en-us;318604

    Have fun.

    Author Comment

    I see your post and I have tried this.  It goes back to another post I have made.  When I use the above to create a new thread, on the db fill a second vertical and a second horizontal scroll bar are created.  I have taken out the winform adapter and created my own and it still creates 2 scroll bars.

    When i use the async call it does not create the dual scroll bars.  i would like to stay with the async call, I just cant figure out why it is locking up the program after the function finishes.  I need to kill the async in order to proceed.  Unless we can figure out why the dual scrolls are showing up
    LVL 6

    Expert Comment

    This is how I used asynchronous processing with delegates which works well for me:

    I define a delegate:

    Public Delegate Sub MyProcessDelegate(parameters)

    I define a class MyProcessClass with a Start, Execute or Run method (however you want to call the processing method).

    Then I define two classes:

    Class MyPreProcess
     Sub Start(parameters)
      Dim pc As New MyProcessClass(parameters)
      pc = Nothing
     End Sub
    End Class

    Class MyPostProcess
     Sub [End](ByVal ar As IAsyncResult)
                Dim pd As MyProcessDelegate = CType(CType(ar, AsyncResult).AsyncDelegate, MyProcessDelegate)
     End Sub
    End Class

    These classes ensure thread safety by taking advantage of encapsulation. This approach is useful especially when you want to launch MyPreProcess.Start more than once so that you have many IAsync threads of MyPreProcess.Start where each instance has its own callback instance of MyPostProcess. Anyways, that will be a bit different and is out of scope for this post. ;-)

    In the main method, I follow more or less this structure:

    Dim ar As IAsyncResult
     Dim prep As New MyPreProcess()
     Dim pd As New MyProcessDelegate(AddressOf prep.Start)
     Dim postp As New MyPostProcess()
     ar = ppaud.BeginInvoke(parameters, New AsyncCallback(AddressOf postp.End), New Object())
    Catch exc As Exception
     ' TODO
     Dim isPending As Boolean = False
      isPending = False
      If Not ar.IsCompleted Then
       isPending = True
      End If
     Loop While isPending
    End Try

    Now this approach works for me because I use this to perform backend processes that does not affect the form. But if you put the form into the picture, so that you can update the datagrid for example, you'll experience the problem described in the article I gave you unless you can work around it. Which should bring you back to MethodInvoker()...
    LVL 6

    Accepted Solution

    Now this is how I did it with the form using MethodInvoker as described in the article:

    I define the following as a global variable in MyModule.vb:

    Public MyDataSet As DataSet

    That means I have a Sub Main entry point in MyModule.

    Then I define this variable in MyForm.vb:

    Private MyFiller As MethodInvoker

    I define these methods in MyForm.vb:

    Private Sub FillMyDataGrid()
     SyncLock Me
       MyDataGrid.SetDataBinding(MyDataSet, "MyDataGrid")
      Catch exc As Exception
       ' TODO
      End Try
     End SyncLock
    End Sub

    Private Sub FillMyDataSet()
     SyncLock MyDataSet
       ' Add you code to fill up MyDataSet
      Catch exc As Exception
       ' TODO
      End Try
     End SyncLock
    End Sub

    Private Sub FillMyDataGridThread()
    End Sub

    Then do this:

    Private Sub MyForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     MyDataSet = New DataSet()
     MyFiller = New MethodInvoker(AddressOf Me.FillMyDataGrid)
    End Sub

    Then I use Thread to launch (maybe in your button click event handler):

    Private Sub Search_Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Search_Btn.Click
     Dim MyFillerThread As New Thread(New ThreadStart(AddressOf Me.FillMyDataGridThread))
     MyFillerThread.IsBackground = True
    End Sub

    This is beautiful and simple though you'll have to do some extra work in order to manage the thread and prevent relaunching it when it is still active.

    Well, Ive presented two approaches to you. What you need now is to maybe put them together (I can imagine you still want IAsync). You can replace the Thread stuffs here with the IAsync approach I showed you. Can you imagine how? Good luck!

    Have fun...

    Author Comment

    Yes, I followed you.
    Now a ? for you.  can you manually kill that IAsync process?  

    I will give it a whirl and see what I come up with. I'll let you know.

    Thank You
    LVL 6

    Expert Comment

    That's precisely the problem with IAsync. You have no control over the thread it creates. If you want control, use Thread.

    Have fun.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Lean Six Sigma Project Manager Certification

    There are many schools of thought around successful project management, but few as highly regarded as the Six Sigma and Lean methods. With 37 hours of learning, this training will explain concrete processes for increasing efficiency and limiting wasted time and effort.

    Suggested Solutions

    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now