Help Thread pooling ???

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear all,

I have a function that I need to run in a thread due to the fact that it can
takes long time to execute according to the amount of data to collect.
This function is also populating a treeview control whne collected data gets
finished.

In order to achieve this I have used the following code :
System.Threading.ThreadPool.QueueUserWorkItem(New
System.Threading.WaitCallback(AddressOf GetListOfReelsFromRemoteDB))

Then my function definition is as follow :

===>>
private sub GetListOfReelsFromRemoteDB
m_objRemoteHist = New Remote(m_sRemoteDbPath)

m_objRemoteHist.Read()
Dim sParam(0) As Object

sParam(0) = m_objRemoteHist
tLogView.Invoke(AddReels, sParam)
Me.Cursor = Cursors.Default
end sub
<<===

The Read routine, collect data froma remote database
When Read return, it populates a tree view control with a delagate object by
using the Invoke.

Problem I have is that when tLogView.Invoke(AddReels,sparam) execute, it
frees my whole application and gets "no responding status". I guess there
shuld be something wrong with the thread queue process but do not know why
and how to solve it

Does anyone could help ?

regards
serge
 
The necessary call to Invoke causes the update of the treeview to execute on
the thread of your form. This means that the UI will be unresponsive while
the treeview is being populated because the main thread is busy.

If you want the UI to be more responsive you might want to try changing the
code so that Invoke is called once for each item instead of once for all
items. This will give the main thread a little extra time to update the UI
inbetween the calls to Invoke. You may have to add some code to handle the
case where the user closes the form while the tree is being populated.

HTH, Jakob.
 
I will give a try.
BUt then how do you explain that my application is freezed with" No
responding" for ever even if my caollected data is a simple and unique row
????

Just for your information, I i am not executing my function in a thred pool,
its clear that my main form is diturbed but it is not freeze at all for ever


thnaks for your help
 
I just try your suggestion use the invoke at each node but it freeze
immediatly for ever.

It freeze as soon as the Invoke line start to be executed
I am stuck indeed out of idea.
 
I wrote a small sample for you. Can you get this working (you need to create
a form with a button and a treeview first)?

Private Sub AddToTreeView(ByVal text As String)
Me.TreeView1.Nodes.Add(text)
End Sub

Delegate Sub AddToTreeViewDelegate(ByVal text As String)

Private Sub ReadData(ByVal state As Object)
Dim callback As New AddToTreeViewDelegate(AddressOf AddToTreeView)
Dim i As Integer
For i = 0 To 100000
Me.Invoke(callback, New Object() {i.ToString()})
Next
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf ReadData))
End Sub

Regards, Jakob.
 
Yes I am able to make it work...

What is the difference between the way I am doing it and your sample then ?
I could not found any.

my treeView is ona main form, the procedure I called in the thread pool is
collecting data froma a remote database (no problem here) and I am populating
the tree when all data from databased gets collected.

Or should I remove the Invoke outside of the threadpool ?

Thanks for your help
Regards
 
Try posting your code (the essential parts) and I will have a look at it.

Regards, Jakob.
 
I start to loose my hairs,
I collect my remote data, which includes 1500 records
At the time the .Invoke is call it suck all times
 
Where can I post it ? directly here or email ?

Dod u thing it could comes from the fact that the object pass in my INvoke,
it too big ?

serge
thnaks for your help
 
Hi jakob, some more info about my trouble.
I have paste only the necessary code into your sample application to see if
I am able to collect and update the treview.
It works reaaly fine.

Then I keep it as it is and do exactly the same thing again from scratch
into my own aplication and same situation occurs, it freeze my all application

According to my test what I have notice is that it freeze, as long as the
Invoke try to execute as following code:

For Each m_Reel In m_objRemoteHist.ListOfReels
Param(0) = m_Reel
Me.tLogView.Invoke(callback, Param)
ProgressBar1.Value = ProgressBar1.Value + 1
Next

I have the remove everything into that callback function, so I have just the
definition and a simple msgbox message inside, it do not even jum to the
message box. For me sounds that it cannot jump to the call back routine or
paramete is badly pass, but it so strange that same sytax works fine on your
code.

I ma lost any more idea or how to debug that stuff ?

thnaks again
serge
 
Hey Serge,

The following two lines taken from your sample looks wrong:

Me.tLogView.Invoke(callback, Param)
ProgressBar1.Value = ProgressBar1.Value + 1

The call to ProgressBar1 is not legal since you are not allowed to call any
controls from another thread. So you have to update the progress bar using
Invoke. What is tLogView? Is that your Windows form?

Regards, Jakob.
 
Hi jakob,

First of all thanks for helping me again.
Second, the tlogView is my treeView control located on my main form
 
Hi,

I finnaly solve the problem. it was causing as you mentionned by the fact of
setting up the progress bar value in the thread

many thnks for you help
Serge
 
Back
Top