473,770 Members | 5,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2010
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*****@nosp am-yahoo.com> wrote in message
news:dh******** **@news.freedom 2surf.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 ListViewUpdater Delegate As New MethodInvoker(A ddressOf
ListViewUpdate)

Then call the Invoke method of the ListView and pass the delegate in:
MyListView.Invo ke(ListViewUpda terDelegate)

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.goo glegroups.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 ListViewUpdater Delegate As New MethodInvoker(A ddressOf
ListViewUpdate)

Then call the Invoke method of the ListView and pass the delegate in:
MyListView.Invo ke(ListViewUpda terDelegate)

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 _ListViewToChan ge 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)
_ListViewToChan ge = 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(A ddressOf DoTheWork)

_ListViewToChan ge.Invoke(Updat eDelegate)
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.ChangeI t("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******** *************@f 14g2000cwb.goog legroups.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 _ListViewToChan ge 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)
_ListViewToChan ge = 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(A ddressOf DoTheWork)

_ListViewToChan ge.Invoke(Updat eDelegate)
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.ChangeI t("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
9669
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 size was changed. How can I make the scrolling content "stick" the position with respect to the scrollowing box? Your advise is appreciated. Spencer
3
4690
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 'window.pageXOffset' and 'window.pageYOffset' are not correct. Is there any other way to get the correct scrolling offsets?
4
3101
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 cache. If the stopPreload() function is activated and the ret val set to false, the preload() function still continues to the end. Any suggestions on how to stop the preload() function in its process, what conditions are necessary?
2
3833
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# Windows MDI Application, as in MSDN, ie : 1) Create Windows Application (Form1), set IsMDIContainer to true 2) Create MainMenu component in the form, with top level '&File', submenu '&New' and '&Close', and another top level '&Window' with MDIList...
3
2054
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 macro, and I ran a command that told the application to process windows messages. Is there such a thing in vb.net, or is there a way to make sure windows messages get processed in big cpu greedy loops? Also, Is it a big deal to make code multy...
2
1197
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 enabled). When I drag a control to the edge of the visible border, I am sending the WM_HSCROLL/WM_VSCROLL message to the parent form to initiate a scroll. This works good, the parent form scrolls and keeps scrolling until the control is dropped or...
7
3199
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
7806
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 find the text and select it using the function below, BUT I can't figure out how to have the textarea automatically scroll to the selection in Firefox. Any ideas or suggestions? function search(needle,haystack,start) { var element =...
0
9591
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10225
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10053
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10001
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3573
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.