473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help Thread pooling ???

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
Jul 21 '05 #1
12 1524
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.
--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:
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

Jul 21 '05 #2
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

"Jakob Christensen" wrote:
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.
--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:
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

Jul 21 '05 #3
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.
"Jakob Christensen" wrote:
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.
--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:
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

Jul 21 '05 #4
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.
--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:
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.
"Jakob Christensen" wrote:
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.
--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:
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

Jul 21 '05 #5
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
"Jakob Christensen" wrote:
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.
--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:
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.
"Jakob Christensen" wrote:
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.
--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:

> 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

Jul 21 '05 #6
Try posting your code (the essential parts) and I will have a look at it.

Regards, Jakob.

--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:
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
"Jakob Christensen" wrote:
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.
--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:
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.
"Jakob Christensen" wrote:

> 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.
> --
> http://www.dotninjas.dk
> http://www.powerbytes.dk
>
>
> "serge calderara" wrote:
>
> > 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

Jul 21 '05 #7

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

"Jakob Christensen" wrote:
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.
--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:
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.
"Jakob Christensen" wrote:
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.
--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:

> 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

Jul 21 '05 #8
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

"Jakob Christensen" wrote:
Try posting your code (the essential parts) and I will have a look at it.

Regards, Jakob.

--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:
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
"Jakob Christensen" wrote:
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.
--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:

> 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.
>
>
> "Jakob Christensen" wrote:
>
> > 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.
> > --
> > http://www.dotninjas.dk
> > http://www.powerbytes.dk
> >
> >
> > "serge calderara" wrote:
> >
> > > 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

Jul 21 '05 #9
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

"Jakob Christensen" wrote:
Try posting your code (the essential parts) and I will have a look at it.

Regards, Jakob.

--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:
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
"Jakob Christensen" wrote:
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.
--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:

> 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.
>
>
> "Jakob Christensen" wrote:
>
> > 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.
> > --
> > http://www.dotninjas.dk
> > http://www.powerbytes.dk
> >
> >
> > "serge calderara" wrote:
> >
> > > 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

Jul 21 '05 #10
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.

--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:
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

"Jakob Christensen" wrote:
Try posting your code (the essential parts) and I will have a look at it.

Regards, Jakob.

--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:
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
"Jakob Christensen" wrote:

> 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.
> --
> http://www.dotninjas.dk
> http://www.powerbytes.dk
>
>
> "serge calderara" wrote:
>
> > 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.
> >
> >
> > "Jakob Christensen" wrote:
> >
> > > 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.
> > > --
> > > http://www.dotninjas.dk
> > > http://www.powerbytes.dk
> > >
> > >
> > > "serge calderara" wrote:
> > >
> > > > 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

Jul 21 '05 #11
Hi jakob,

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

"Jakob Christensen" wrote:
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.

--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:
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

"Jakob Christensen" wrote:
Try posting your code (the essential parts) and I will have a look at it.

Regards, Jakob.

--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:

> 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
>
>
> "Jakob Christensen" wrote:
>
> > 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.
> > --
> > http://www.dotninjas.dk
> > http://www.powerbytes.dk
> >
> >
> > "serge calderara" wrote:
> >
> > > 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.
> > >
> > >
> > > "Jakob Christensen" wrote:
> > >
> > > > 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.
> > > > --
> > > > http://www.dotninjas.dk
> > > > http://www.powerbytes.dk
> > > >
> > > >
> > > > "serge calderara" wrote:
> > > >
> > > > > 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

Jul 21 '05 #12
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

"Jakob Christensen" wrote:
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.

--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:
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

"Jakob Christensen" wrote:
Try posting your code (the essential parts) and I will have a look at it.

Regards, Jakob.

--
http://www.dotninjas.dk
http://www.powerbytes.dk
"serge calderara" wrote:

> 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
>
>
> "Jakob Christensen" wrote:
>
> > 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.
> > --
> > http://www.dotninjas.dk
> > http://www.powerbytes.dk
> >
> >
> > "serge calderara" wrote:
> >
> > > 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.
> > >
> > >
> > > "Jakob Christensen" wrote:
> > >
> > > > 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.
> > > > --
> > > > http://www.dotninjas.dk
> > > > http://www.powerbytes.dk
> > > >
> > > >
> > > > "serge calderara" wrote:
> > > >
> > > > > 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

Jul 21 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: AlexeiOst | last post by:
Everywhere in documentation there are recommendations to use threads from thread pooling for relatively short tasks. As I understand, fetching a page or multiple pages (sometimes up to 50 but not...
12
by: serge calderara | last post by:
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...
5
by: Jim Stools | last post by:
Newbie question: Hopefully I worded this correctly... Does each instance of an aspx page spawn its own thread? If so are the threads protected? I assume each aspx page is processed in a...
5
by: jzlondon | last post by:
Hi, I have a question that I wonder if someone might be able to help me with... I have an application which handles real-time financial data from a third party source. The data comes in via...
10
by: Jon Slaughter | last post by:
Since a thread doesn't have a Stop feature and I'm not supose to use abort, I'm wondering how I stop a thread? My problem is that I simply want to excute a function in the background and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.