> Alexandros' reply referred to "delegates". I had never used one, but=20 > need to do something with a .net SerialPort object, because the=20 > DataReceived event is not on the main thread. I thought I understood=20 > M$oft VC++ delegates after implementing the example here:=20 > > Sadly, I don't understand the indirection used in these lines: >=20 > delegate void AddListItem(); > AddListItem^ myDelegate; > ... > myDelegate =3D gcnew AddListItem( this, &Form1::AddListItemMethod ); > ... > myForm->Invoke( myForm->myDelegate ); >=20 > and trying to invoke the delegate from a class that has no knowledge of=20 > the Form Class is not easy for me. > --=20 Think of a delegate as a smart function pointer that also knows about the=20 object that holds the function. This means that the function does not need = to=20 be static. A delegate is actually a class that holds information about the signature o= f a=20 function and possibly also about the object where the function is going to = be=20 invoked. The delegate needs to be instantiated into an object that then tak= es=20 care of interthread marshalling if needed. The class invoking the function through the delegate does not need to know= =20 anything about the class where the function is going to be invoked if it is= an=20 object of that class that tells the delegate which function is going to be= =20 invoked. This is usually the case for Events where the class has a function= =20 that is to be called at a specific event raised by another object. In this = case=20 the object is said to subscribe to the event. For the SerialPort class and the DataReceived event the case is a bit=20 different. Here the DataReceived event is part of a class (perhaps a form o= r=20 control) but it is running in a separate thread and the delegate needs to b= e=20 used in order to call another function in the same class but needs to do it= =20 thread safely. In this case the DataReceived event knows about the class wh= ere=20 the function is to be invoked since it is part of the same class. Because o= f=20 this the delegate object can be instantiated by the DataReceived event func= tion=20 in itself.=20 I usually have my SerialPort class belong to a form with controls (e.g. tex= t=20 boxes and labels) that is updated with information about the current state = of=20 the communication. This form is usually invisible and only showed when trou= ble=20 shooting. When the DataReceive event is raised it needs to use delegates to= =20 call a function which is running in the GUI thread for that form. The=20 DataReceive event does not call this function until it has received a compl= ete=20 telegram. /Ruben =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D Ruben J=F6nsson AB Liros Electronic Box 9124, 200 39 Malm=F6, Sweden TEL INT +46 40142078 FAX INT +46 40947388 ruben@pp.sbbs.se =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .