3

El código que tengo es el siguiente:

Thread NewThread = new Thread(new ThreadStart(MethodInThread));
NewThread.Start(MyKitchen);

public static void MethodInThread()
{
    //Mostrar datos de parámetros
}
0

1 respuesta 1

4

Te aconsejo usar hilos parametrizados con la clase ParameterizedThreadStart. Te expongo un ejemplo de código:

class Program
{
    static void Main(string[] args)
    {
        Kitchen MyKitchen = new Kitchen()
        {
             HasOven = true,
              Size = "36 m2",
        };

        Thread NewThread = new Thread(new ParameterizedThreadStart(MethodInThread));
        NewThread.Start(MyKitchen);

        Console.Read();

        NewThread.Abort();
    }

    public static void MethodInThread(object AnyObject)
    {
        Kitchen ExistingKitchen = AnyObject as Kitchen;

        Console.WriteLine(ExistingKitchen.Size);
        Console.WriteLine(ExistingKitchen.HasOven);
    }
}

public class Kitchen
{
    public string Size { get; set; }
    public bool HasOven { get; set; }
}

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.