The code is as follows, below the explanation ..
Thread hilo = new Thread(NuevoHilo);
hilo.Start(item);
private void NuevoHilo(object item)
{
rtxMensajes = new Mensajes().NuevoMensaje(rtxMensajes, item.ToString(), tbxArchivo.Text, Color.Green);
}
public RichTextBox NuevoMensaje(RichTextBox rtb, string unidad, string archivo, Color color)
{
string avance = "\r\n";
rtb.SelectionStart = rtb.TextLength; <---- EXCEPCION!!!
rtb.SelectionLength = 0;
rtb.SelectionColor = color;
rtb.AppendText(String.Format("Se copio el archivo {0} en la unidad {1} {2}", archivo, unidad, avance));
rtb.SelectionColor = rtb.ForeColor;
return rtb;
}
When the NuevoHilo
method is executed and this instance is an object of the class Mensaje
which in turn calls a method of this class and takes as parameter a RichTextBox
object, an exception of type System.InvalidOperationException
, which gives me the following description;
Invalid operation through sub-processes: The 'rtxMessages' control was accessed from a different sub-process than the one in which it was created.
To say that the object that I pass as a parameter is a RichTextBox that I have created in Form1, I try that every time I throw the thread I write the result in RichTextBox called rtxMensajes