[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

No Progress showing during adapt.fill

Posted on 2004-10-25
9
Medium Priority
?
347 Views
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
XP
1 gig ram

? any ideas?

The search that it is performing is running through 300,000 records.
0
Comment
Question by:malanois
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 8

Expert Comment

by:bramsquad
ID: 12402797
did you make sure to add

Application.DoEvents()

in your loop?

~b
0
 

Author Comment

by:malanois
ID: 12403382
yes it is there
0
 

Author Comment

by:malanois
ID: 12404741
I have tried this post

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21056447.html#11536181

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
        Me.DataGrid.Show()
        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
        Else
            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"

            Me.OleDbDataAdapter1.Fill(Me.DbDataSet)
            '// Do your work here
        End If

    End Function



Any thoughts???








0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:etmendz
ID: 12407941
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:

http://support.microsoft.com/default.aspx?scid=kb;en-us;318604

Have fun.
0
 

Author Comment

by:malanois
ID: 12410562
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
0
 
LVL 6

Expert Comment

by:etmendz
ID: 12417671
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.Start()
  pc = Nothing
 End Sub
End Class

Class MyPostProcess
 Sub [End](ByVal ar As IAsyncResult)
            Dim pd As MyProcessDelegate = CType(CType(ar, AsyncResult).AsyncDelegate, MyProcessDelegate)
            pd.EndInvoke(ar)
 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
Try
 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
Finally
 Dim isPending As Boolean = False
 Do
  Thread.Sleep(TimeSpan.FromSeconds(5))
  Application.DoEvents()
  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()...
0
 
LVL 6

Accepted Solution

by:
etmendz earned 2000 total points
ID: 12417788
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
  Try
   MyDataGrid.SetDataBinding(MyDataSet, "MyDataGrid")
  Catch exc As Exception
   ' TODO
  End Try
 End SyncLock
End Sub

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

Private Sub FillMyDataGridThread()
 FillMyDataSet()
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
 MyFillerThread.Start()
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...
0
 

Author Comment

by:malanois
ID: 12421005
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
0
 
LVL 6

Expert Comment

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

Have fun.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

650 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