C sharp - Programa con threads

 
Vista:

Programa con threads

Publicado por Nahuel pelecano (1 intervención) el 05/05/2019 23:49:19
Hola necesito hacer para el colegio un programa en c# con hilos , es básico pero no se nada sobre hilos. Les dejo el enunciado a ver si alguien em puede ayudar:
Hacer un programa con 3 threads que cuenten hasta 10000 conjuntamente luego mostrar en pantalla cuanto contó cada thread. Si alguien tiene idea como se hace se lo agradeceria muchisimo vi tutoriales pero ninguno explicaba nada relacionado con esto .
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Programa con threads

Publicado por E (4 intervenciones) el 06/05/2019 04:50:03
Una clase para usar threads:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public delegate void FooBarDelegate();
 
public class ActionDelegateThreads
{
    private FooBarDelegate _action;
    private FooBarDelegate _postaction;
 
    public void ActionDelegate(FooBarDelegate action, FooBarDelegate postaction)
    {
        _action = action;
        _postaction = postaction;
 
        Thread t = new Thread(ejecutar);
        t.SetApartmentState(ApartmentState.STA);
 
        t.Start();
    }
 
    private void ejecutar()
    {
        if (_action != null)
            _action();
 
        Application.Current.Dispatcher.Invoke((Action)delegate
        {
            if (_postaction != null)
                _postaction();
        });
    }
}

Como se usa:

1
acc = new ActionDelegateThreads().ActionDelegate(tuaccion, tuaccionpost);
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar