473,324 Members | 2,541 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,324 software developers and data experts.

Keep loop running whilst scrolling or moving the window

Hi all.

I have a VB.NET app with a loop running that is continually managing a
number of threads AND updating a ListView object depending on the results of
the worker threads.

The problem I have is that if I try to move (drag) the form's window around
the screen, or to scroll the ListView control, the loop pauses until I stop
dragging or scrolling. I want the loop to continue whilst I'm doing trivial
things like moving the window around the screen.

Is there a way to do this?

I cannot move the loop to another thread, as I need the loop to update the
ListView, and it must therefore run in the same thread that created the
ListView object. I have already tried putting DoEvents() and Thread.Sleep()
commands into the loop.

Many thanks in advance,
Wicksy.
Nov 21 '05 #1
5 1982
PS. I think what I'm asking is is there a way to stop the form (or the
ListView) from blocking whilst it is being dragged/resized/whatever?

"Wicksy" <wi*****@nospam-yahoo.com> wrote in message
news:dh**********@news.freedom2surf.net...
Hi all.

I have a VB.NET app with a loop running that is continually managing a
number of threads AND updating a ListView object depending on the results
of the worker threads.

The problem I have is that if I try to move (drag) the form's window
around the screen, or to scroll the ListView control, the loop pauses
until I stop dragging or scrolling. I want the loop to continue whilst I'm
doing trivial things like moving the window around the screen.

Is there a way to do this?

I cannot move the loop to another thread, as I need the loop to update the
ListView, and it must therefore run in the same thread that created the
ListView object. I have already tried putting DoEvents() and
Thread.Sleep() commands into the loop.

Many thanks in advance,
Wicksy.

Nov 21 '05 #2
Wicksy wrote:
I cannot move the loop to another thread, as I need the loop to update the
ListView, and it must therefore run in the same thread that created the
ListView object. I have already tried putting DoEvents() and Thread.Sleep()
commands into the loop.


But you can! You just need to make sure you marshal the call to update
the UI to the UI thread.

The simplest way is to create a sub that updates the control and then
use a MethodInvoker delegate in conjunction with the ListView's Invoke
method to call it:

'ListViewUpdate contains code to update the list view.
Dim ListViewUpdaterDelegate As New MethodInvoker(AddressOf
ListViewUpdate)

Then call the Invoke method of the ListView and pass the delegate in:
MyListView.Invoke(ListViewUpdaterDelegate)

This may not be the best method to use, depending on your needs, but
look up the Control.Invoke and MethodInvoker in the docs.

Nov 21 '05 #3
Hi Chris...
How would I pass parameters to that delegate function?
(this is where i start getting confused...)
"Chris Dunaway" <du******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Wicksy wrote:
I cannot move the loop to another thread, as I need the loop to update
the
ListView, and it must therefore run in the same thread that created the
ListView object. I have already tried putting DoEvents() and
Thread.Sleep()
commands into the loop.


But you can! You just need to make sure you marshal the call to update
the UI to the UI thread.

The simplest way is to create a sub that updates the control and then
use a MethodInvoker delegate in conjunction with the ListView's Invoke
method to call it:

'ListViewUpdate contains code to update the list view.
Dim ListViewUpdaterDelegate As New MethodInvoker(AddressOf
ListViewUpdate)

Then call the Invoke method of the ListView and pass the delegate in:
MyListView.Invoke(ListViewUpdaterDelegate)

This may not be the best method to use, depending on your needs, but
look up the Control.Invoke and MethodInvoker in the docs.

Nov 21 '05 #4
Wicksy wrote:
Hi Chris...
How would I pass parameters to that delegate function?
(this is where i start getting confused...)


Using that method, you can't. You would have to create a wrapper class
with properties that also has the delegate. Then you set the
properties of the class. Perhaps something like this (untested):

Public Class ListViewChanger

Private _ListViewToChange As ListView
Private _SomeString As String
Private _SomeInteger As Integer

'The control we want to change is passed into the class
'In this case it is a listview
Public Sub New(ByVal lvtochange As ListView)
_ListViewToChange = lvtochange
End Sub

'This is the method that you call that will use a delegate to
upadate the
'ListView.
Public Sub ChangeIt(ByVal s As String, ByVal i As Integer)
'These variables hold the data that you need passed in.
_SomeString = s
_SomeInteger = i

Dim UpdateDelegate As New MethodInvoker(AddressOf DoTheWork)

_ListViewToChange.Invoke(UpdateDelegate)
End Sub

Private Sub DoTheWork()
'Here you would do whatever to update the ListView. You would
then
'access any properties that were passed in.
End Sub
End Class

You would create an instance of this class and pass your ListView into
the constructor:

Dim Changer As New ListViewChanger(MyListView)
Changer.ChangeIt("Hello", 123)

Hope this gives you some ideas.

Nov 21 '05 #5
brilliant!
very clear - probably the best explanation i've seen yet!
thanks very much.
"Chris Dunaway" <du******@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Wicksy wrote:
Hi Chris...
How would I pass parameters to that delegate function?
(this is where i start getting confused...)


Using that method, you can't. You would have to create a wrapper class
with properties that also has the delegate. Then you set the
properties of the class. Perhaps something like this (untested):

Public Class ListViewChanger

Private _ListViewToChange As ListView
Private _SomeString As String
Private _SomeInteger As Integer

'The control we want to change is passed into the class
'In this case it is a listview
Public Sub New(ByVal lvtochange As ListView)
_ListViewToChange = lvtochange
End Sub

'This is the method that you call that will use a delegate to
upadate the
'ListView.
Public Sub ChangeIt(ByVal s As String, ByVal i As Integer)
'These variables hold the data that you need passed in.
_SomeString = s
_SomeInteger = i

Dim UpdateDelegate As New MethodInvoker(AddressOf DoTheWork)

_ListViewToChange.Invoke(UpdateDelegate)
End Sub

Private Sub DoTheWork()
'Here you would do whatever to update the ListView. You would
then
'access any properties that were passed in.
End Sub
End Class

You would create an instance of this class and pass your ListView into
the constructor:

Dim Changer As New ListViewChanger(MyListView)
Changer.ChangeIt("Hello", 123)

Hope this gives you some ideas.

Nov 21 '05 #6

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

Similar topics

3
by: spencer | last post by:
Hello, I have an index page with an autoscroller writen with CSS. The problem is the scrolling content(text and inages)'s position is correct but will off position when the broswer(IE) window...
3
by: Vikram Bhatia | last post by:
1. Is there an event to capture scrolling using mouse wheel in Netscape 6.x? 2. When arrow keys are used to scroll a page in Netscape 6.x, the scrolling offsets obtained using...
4
by: David | last post by:
Hi everyone, I am trying to stop an image preload sequence by the click of a mouse but have been unsuccessful trying several methods. Imagine this simple script below that loads 50 images to...
2
by: James CC | last post by:
I have a strange bug in C# using windows forms. To make sure it's not some bug with my code, I've gone back to a simple test app, and still see the same behavior. I have created a simple C#...
3
by: Fred Flintstone | last post by:
I have a project, that loops through a lot of wmi queries, and while its looping, the window will not repaint, I can't move or size the window. I remember having a similar problem back in an excel...
2
by: Jonathan | last post by:
I have a form that has controls on it that can be dragged to other locations within the form. The form size is larger than the viewable area so the scroll bars are visible (and autoscroll is...
7
by: DaVinci | last post by:
I am writing a pong game.but met some problem. the ball function to control the scrolling ball, void ball(int starty,int startx) { int di ,i; int dj,j; di = 1; dj = 1; i = starty;
4
by: Keith Bentrup | last post by:
Hi all, I wrote a simple search function to find text in a textarea where not all the text is visible (ie. the text box displays 10 lines but there may be more than 1000 lines to search). I can...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.