472,779 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 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 1940
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.