Listview Cursor and Thread

  • Thread starter Thread starter Claudio Di Flumeri
  • Start date Start date
C

Claudio Di Flumeri

I am filling a listview with some data read from a Database SQL Server. To
fill the listview I am using a thread in which I read data from DB and I add
them to the listview. The problem is that, when the thread is executing,
when I move the cursor over the listview the Default Cursor is shown while
the WaitCursor had to be shown (just like happen over the remaining part of
the interface of my program). I have set the cursor (the one of the form,
not the one of the listview because I've read it doesn't work and anyway
I've tried that too) to WaitCursor both before and inside the thread, but
nothing happens. Any idea?
 
Hi Claudio,

What is the reason you do it this way normaly this should be slower and
means that it is spending more resources from your system?

Cor
 
* "Claudio Di Flumeri said:
I am filling a listview with some data read from a Database SQL Server. To
fill the listview I am using a thread in which I read data from DB and I add
them to the listview. The problem is that, when the thread is executing,
when I move the cursor over the listview the Default Cursor is shown while
the WaitCursor had to be shown (just like happen over the remaining part of
the interface of my program). I have set the cursor (the one of the form,
not the one of the listview because I've read it doesn't work and anyway
I've tried that too) to WaitCursor both before and inside the thread, but
nothing happens. Any idea?

Did you set 'Cursor.Current'? Do you access properties/methods of the
form from within the other thead? That doesn't work, you will have to
invoke the methods instead of calling them directly (have a look at the
controls' 'Invoke', 'BeginInvoke', and 'EndInvoke' methods).
 
I'm using a thread for a refresh problem, the operation of filling the
listview takes a while and I want to allow the user to stop it / resume it
and so on.
 
Hmmm. I'm doing almost exactly the same thing in my software. Executing
delegate on the control from the thread in order to refresh the item.
 
I'm doing something like this

Private Sub ShowCursor()
Me.Cursor = Cursors.WaitCursor()
End Sub

Private Sub MyThread()
Me.BeginInvoke(New MethodInvoker(AddressOf ShowCursor))

'Here I fill the ListView
...
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim t_MyThread As New Thread(New ThreadStart(AddressOf MyThread)))

t_MyThread.Start()
End Sub

And no WaitCursor is shown (over the listview) when thread is executed!

Herfried K. Wagner said:
Did you set 'Cursor.Current'? Do you access properties/methods of the
form from within the other thead? That doesn't work, you will have to
invoke the methods instead of calling them directly (have a look at the
controls' 'Invoke', 'BeginInvoke', and 'EndInvoke' methods).
End Sub
 
I'm using a thread for a refresh problem, the operation of filling the
listview takes a while and I want to allow the user to stop it / resume it
and so on.

And what is than processing meanwhile that the listview is filling, I think
the only thing that can be done for a user is waiting until the listview is
filled and to interfear he needs an application.doevents anyhow, so that can
in the mainthread also.

Cor
 
Back
Top