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

Accessing controls from another thread

Hi there,

Previously in 1.1 .NET Framework if you were to access a control from
another thread you would not recieve an exception by default, instead it was
down to you and/or the control to prevent anything untoward happening.

Anyway, in 2.0 an exception is thrown the second you attempt to do this.
So I'm replacing large chunks of code to remove this problem. The only
thing is I would like to check that I am using the correct procedure.

I am calling the invoke method of the form that created the control.
The only problem here is that if the method requires parameters I need to
pass them in an array of objects...

Private sub changeControlsProperties(Byval iArgs() as Object)
Dim pStrString as String = CStr(iArgs(0))
Dim pIntInteger as Integer = CInt(IArgs(1))
... so on and so fourth and such like ...
End Sub

This doesn't seem like a very nice way to be calling a method so I'm
wondering if anyone knows of any other techniques for handling this "cross
threading" issue.

Nick.
Feb 3 '06 #1
1 1309
Hi again,

What I have ended up doing is strictly declaring the delegate methods,
although this isn't exactly what I was after it does what is required.

---------------

'//Declaration space

Delegate Sub changeControlPropertiesDelegate(Byval iString as String,
Byval iInteger as Integer)

Private cDelChangeControlProperties as New
changeControlPropertiesDelegate(AddressOf changeControlProperties)

Private sub changeControlProperties(Byval iString as String, Byval
iInteger as Integer)
'//Apply properties to control
Exit Sub

'//From some other thread
Dim pObjParams() as Object = {"This is a test", 1001)
Call Invoke(cDelChangeControlProperties, pObjParams)

---------------

Nick.

"Nick Pateman" <a@a.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi there,

Previously in 1.1 .NET Framework if you were to access a control from
another thread you would not recieve an exception by default, instead it
was down to you and/or the control to prevent anything untoward happening.

Anyway, in 2.0 an exception is thrown the second you attempt to do
this. So I'm replacing large chunks of code to remove this problem. The
only thing is I would like to check that I am using the correct procedure.

I am calling the invoke method of the form that created the control.
The only problem here is that if the method requires parameters I need to
pass them in an array of objects...

Private sub changeControlsProperties(Byval iArgs() as Object)
Dim pStrString as String = CStr(iArgs(0))
Dim pIntInteger as Integer = CInt(IArgs(1))
... so on and so fourth and such like ...
End Sub

This doesn't seem like a very nice way to be calling a method so I'm
wondering if anyone knows of any other techniques for handling this "cross
threading" issue.

Nick.

Feb 3 '06 #2

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

Similar topics

3
by: NickP | last post by:
Hi there, This might sound like a stupid question but this whole exception being thrown when accessing user controls from another thread is extremely over the top! Just looking at the index...
5
by: Roman | last post by:
Hello i have main mdi parent window from which i want to load a form, but during creating form object and later calling its Show method i want to display progress and have the main window...
0
by: khalid sohail | last post by:
hi can any1 help me in accessing controls that exist in datagrid using the javascript.......ordinary that controls are access by the document.getelementById('controlid') mathod but that does not...
0
by: khalid sohail | last post by:
hi can any1 help me in accessing controls that exist in datagrid using the javascript.......ordinary that controls are access by the document.getelementById('controlid') mathod but that does not...
9
by: cgwalters | last post by:
Hi, I've recently been working on an application which does quite a bit of searching through large data structures and string matching, and I was thinking that it would help to put some of this...
5
by: Sin Jeong-hun | last post by:
class Engine { Thread Worker; public event ... EngineMessage; public void Start() { Worker=new Thread(new ThreadStart(Run)); Worker.Start(); } private Run()
10
by: Paul E Collins | last post by:
I want to fill an ImageList with bitmaps for a ListView from another thread, because it's a time-consuming process. I expect the ListViewItems' images to "load" one by one, as in a Web browser. ...
0
by: Jon | last post by:
Hi, "THREAD_UI" = thread under which the UI controls were created. "THREAD_XX" = another thread. "FUNC_UI" = function that needs to run on THREAD_UI. From THREAD_XX I need to start the...
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: 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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.