|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Accessing controls from another threadPreviously 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. 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. Show quoteHide quote "Nick Pateman" <a@a.com> wrote in message news:%23FBvsKKKGHA.3960@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. >
Search Arraylist in Arraylist.
Newbie Question: How To Open A File Non-Exclusively? Saving a Database to Disk PropertyBag in VB.NET? Windows Form Application Help Command line argument in NET Prog execution in IDE works, fails when running exe unexpected split functionality - index out of bounds Executing a DTS package VS2005-VB Viewing 'Main' for MDIParent |
|||||||||||||||||||||||