C # Activating Streams

I have this code in C #:

Thread t1 = new Thread(functionsActivations(3, 4000, 0, 4));
Thread t2 = new Thread(functionsActivations(3, 4000, 5, 9));
t1.start();
t2.Start();
Thread t3 = new Thread(functionsActivations(4, 4000, 0, 4));
Thread t4 = new Thread(functionsActivations(4, 4000, 5, 9));

He does not work. How can I say to call the method that I gave him? Secondly, I want t3 and t4 to be activated after the completion of t1 and t2. How can i do this? Thirdly, I want t1 and t2 not to block (so t2 did not have to wait for t1 to end). What did i do right?

+5
source share
1 answer

β€œIt doesn't work” is not a very clear set of symptoms. What are you watching?

EDIT: , , , , . . , , - :

# 2:

Thread t1 = new Thread(delegate() { functionsActivations(3, 4000, 0, 4); });

# 3:

Thread t1 = new Thread(() => functionsActivations(3, 4000, 0, 4));

, - , :

private static Action DeferFunctionActivations(int a, int b, int c, int d)
{
    return () => functionsActivations(a, b, d, d);
}

:

Thread t1 = new Thread(DeferFunctionActivations(3, 4000, 0, 4));

.

# 3.

, t1.start() t1.start() - # .

, t1 t2 - , - , .

, t3 t4 , t1 t2, Thread.Join:

Thread t1 = new Thread(() => functionsActivations(3, 4000, 0, 4));
Thread t2 = new Thread(() => functionsActivations(3, 4000, 5, 9));
t1.Start();
t2.Start();
t1.Join();
t2.Join();
Thread t3 = new Thread(() => functionsActivations(4, 4000, 0, 4));
Thread t4 = new Thread(() => functionsActivations(4, 4000, 5, 9));
t3.Start();
t4.Start();

, , t1 t2. , , - t1 t2. , , :

Thread t1 = new Thread(() => functionsActivations(3, 4000, 0, 4));
Thread t2 = new Thread(() => functionsActivations(3, 4000, 5, 9));
t1.Start();
t2.Start();
Thread t3 = new Thread(() => functionsActivations(4, 4000, 0, 4));
Thread t4 = new Thread(() => functionsActivations(4, 4000, 5, 9));
Thread t5 = new Thread(() =>
{
    t1.Join();
    t2.Join();
    t3.Start();
    t4.Start();
});
t5.Start();

, .

.NET 4.0? , .

+4

All Articles