Hello
I have a form which contains a Listview control that is filled with data as
the program runs. This all works fine, but I want to also then do a certain
process on this data at the same time.
Because of the way the data is received into the control (from an event out
of my hands) my processing causes problems as it is time-intensive. So, I
figure my processing should go in a separate thread so it can work without
stopping the information coming into the 'box. So far so good.
But how do I read and modify the items in the ListView from the other
thread? I have just started moving the code into another class that will
become the new thread and my control name gets underlined as not being
declared. Putting the form name in front (i.e. myForm.lstProgr ess) also
won't work.
Any thoughts? I saw an article on oassing data to and from threads with
callbacks and so on but will this work to link directly to a control?
Thanks
James. 3 1447
"JamesB" <ja***@spamiscr appy.puffle.co. spam.uk> schrieb: I have a form which contains a Listview control that is filled with data as the program runs. This all works fine, but I want to also then do a certain process on this data at the same time. Because of the way the data is received into the control (from an event out of my hands) my processing causes problems as it is time-intensive. So, I figure my processing should go in a separate thread so it can work without stopping the information coming into the 'box. So far so good. But how do I read and modify the items in the ListView from the other thread? I have just started moving the code into another class that will become the new thread and my control name gets underlined as not being declared. Putting the form name in front (i.e. myForm.lstProgr ess) also won't work.
You'll have to pass a reference which points to the form's or control's
instance to the second class. Note that you must not access the
form/control from another thread directly. Instead, use
'Control.Invoke Required', 'Control.Invoke ', and 'Control.BeginI nvoke':
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=multithread ing&lang=en>
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Hi,
Since you can pass a refernce to the listview when you start a
thread you need to create a class that will handle it for you. Try
something like this.
Public Class MyThreadHelper
Dim mlv As ListView
Dim trd As Threading.Threa d
Public Sub New(ByRef lv As ListView)
mlv = lv
End Sub
Public Sub startthread()
If trd Is Nothing Then trd = New Threading.Threa d(AddressOf mylongprocess)
trd.Start()
End Sub
Private Sub mylongprocess()
' use mlv to access the listview
End Sub
End Class
Ken
---------------------
"JamesB" <ja***@spamiscr appy.puffle.co. spam.uk> wrote in message
news:43******** *************** @news.zen.co.uk ... Hello
I have a form which contains a Listview control that is filled with data as the program runs. This all works fine, but I want to also then do a certain process on this data at the same time. Because of the way the data is received into the control (from an event out of my hands) my processing causes problems as it is time-intensive. So, I figure my processing should go in a separate thread so it can work without stopping the information coming into the 'box. So far so good. But how do I read and modify the items in the ListView from the other thread? I have just started moving the code into another class that will become the new thread and my control name gets underlined as not being declared. Putting the form name in front (i.e. myForm.lstProgr ess) also won't work. Any thoughts? I saw an article on oassing data to and from threads with callbacks and so on but will this work to link directly to a control? Thanks James.
"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote in message
news:uX******** ******@TK2MSFTN GP09.phx.gbl... Hi,
Since you can pass a refernce to the listview when you start a thread you need to create a class that will handle it for you. Try something like this.
Thanks to both of you, the reference idea seems to work a treat. I'll now
look through the link Herfried gave to make sure it's reliable.
James. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: dixie |
last post by:
I have some code that adds new records into a table for each ID in a list
box when a button on a form is clicked. This works fine. My problem now is
that I wish to be able to edit all the records for people whose ID is in the
list box. I made minor changes to the code (mainly replacing rs.AddNew with
rs.Edit)and it appears to be updating only the first record and then
overwriting that record with the next, etc until it runs out of ID's...
|
by: Ayende Rahien |
last post by:
Excetremely annoying problem, I've an application with a long startup time.
So I created another form with my logo in it to as a splash screen.
The splash screen is run from another thread and is communicated solely
through static method and Invoke()'s
However, when I close my second form, the first one (main window) is hiding
under all the windows on the desktop.
If I don't close the splash screen, then everything is fine.
I tried...
|
by: Stephen Brooker |
last post by:
Hi all,
I've got a basic TCP app that is giving me trouble. I have a separate
class that takes care of the TCP connection, and uses the NetworkStreams
BeginRead and EndRead with a callback function to deal with the server
response. All works well and the data is received OK. Once all the data
is received, the connection is closed and I fire an event indicating all
is finished. The event is handled in the main form of the application
and...
|
by: Schultz |
last post by:
is there an easy to follow, source code in one document, article that
explains how to create an edit all DataGrid control?
and, I have a DataGrid setup where the client enters information for
each row by clicking Edit-Update for each row. Each row has several
columns, is there anyway to move the Edit function to edit each column
individually for each row in the DataGrid?
|
by: Stephen Rice |
last post by:
Hi,
I have a periodic problem which I am having a real time trying to sort.
Background:
An MDI VB app with a DB on SQL 2000.
I have wrapped all the DB access into an object which spawns a thread to
access the database and then displays a modal dialog which allows the user
to cancel the task, if it is taking longer than they want, and shows them a
display of how long the query has been running so far.
| |
by: Peter |
last post by:
(VS 2003)
I have a DataGrid and accept button. My problem is when a user starts to
edit one of the values in the grid and does not either press Enter or move
of the current cell and presses the Accept buton the current typed value
does not get passed into the grid, but stays in the edit mode. How can I
move the current edit value into the grid without requireing user to press
Enter or move to a different cell?
Thanks
|
by: rn5a |
last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB
table. Users can modify the records using this DataGrid for which I am
using EditCommandColumn in the DataGrid. This is the code:
<script runat="server">
Dim sqlConn As New SqlConnection(".....")
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (Page.IsPostBack) Then
FillDataGrid()
|
by: bhcob1 |
last post by:
Hey guys,
'Update or CancelUpdate without AddNew or Edit'
On my database i keep occasionly get this error when i try and edit a field, it is not everytime. It will be working fine and then this error appears. I will be editing records and then a random one will get the error.
A bit of background on my form, this will seem a bit lengthy but here is my code.
The form has a navigation list which the user can select a record to view.
An...
|
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= |
last post by:
Hi,
i have a main thread an another worker thread.
The main Thread creates another thread and waits
for the threads signal to continue the main thread.
Everything works inside a ModalDialog and everyting
is secured by Invoke/BeginInvoke, and synchronisation
primitves like WaitHandles, Evetns, Semaphores, etc...
All works good and with no race conditions or locks.
I have a System.Windows.Forms.Timer in the main
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |