473,320 Members | 1,922 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,320 software developers and data experts.

Edit a Forms control data from a second thread?

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.lstProgress) 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.
Dec 15 '05 #1
3 1419
"JamesB" <ja***@spamiscrappy.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.lstProgress) 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.InvokeRequired', 'Control.Invoke', and 'Control.BeginInvoke':

<URL:http://dotnet.mvps.org/dotnet/faqs/?id=multithreading&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 15 '05 #2
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.Thread

Public Sub New(ByRef lv As ListView)

mlv = lv

End Sub

Public Sub startthread()

If trd Is Nothing Then trd = New Threading.Thread(AddressOf mylongprocess)

trd.Start()

End Sub

Private Sub mylongprocess()

' use mlv to access the listview

End Sub

End Class

Ken

---------------------
"JamesB" <ja***@spamiscrappy.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.lstProgress) 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.

Dec 15 '05 #3

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uX**************@TK2MSFTNGP09.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.
Dec 15 '05 #4

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

Similar topics

25
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...
6
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...
6
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...
3
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...
8
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...
4
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...
9
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...
9
bhcob1
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...
4
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
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)...
0
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.