Click here to Skip to main content
15,917,005 members
Home / Discussions / C#
   

C#

 
AnswerRe: Program Help Pin
OriginalGriff11-Aug-18 19:31
mveOriginalGriff11-Aug-18 19:31 
GeneralRe: Program Help Pin
Bloodyway11-Aug-18 19:47
Bloodyway11-Aug-18 19:47 
GeneralRe: Program Help Pin
OriginalGriff11-Aug-18 20:08
mveOriginalGriff11-Aug-18 20:08 
GeneralRe: Program Help Pin
AnotherKen18-Aug-18 9:04
professionalAnotherKen18-Aug-18 9:04 
GeneralRe: Program Help Pin
Mycroft Holmes18-Aug-18 13:30
professionalMycroft Holmes18-Aug-18 13:30 
GeneralRe: Program Help Pin
AnotherKen18-Aug-18 19:18
professionalAnotherKen18-Aug-18 19:18 
AnswerRe: Program Help Pin
Richard Andrew x6412-Aug-18 3:32
professionalRichard Andrew x6412-Aug-18 3:32 
QuestionSplit a number into multiple number in a specific way Pin
Mou_kol10-Aug-18 11:14
Mou_kol10-Aug-18 11:14 
AnswerRe: Number distribution in a specific way Pin
Mycroft Holmes10-Aug-18 13:34
professionalMycroft Holmes10-Aug-18 13:34 
AnswerRe: Number distribution in a specific way Pin
Luc Pattyn11-Aug-18 6:22
sitebuilderLuc Pattyn11-Aug-18 6:22 
QuestionGet file metada Pin
Member 1193763910-Aug-18 0:04
Member 1193763910-Aug-18 0:04 
AnswerRe: Get file metada Pin
Richard MacCutchan10-Aug-18 0:22
mveRichard MacCutchan10-Aug-18 0:22 
QuestionRDP connections in tabs Pin
Member 114416229-Aug-18 19:41
Member 114416229-Aug-18 19:41 
AnswerRe: RDP connections in tabs Pin
Mycroft Holmes9-Aug-18 20:20
professionalMycroft Holmes9-Aug-18 20:20 
GeneralRe: RDP connections in tabs Pin
Member 1144162212-Aug-18 23:54
Member 1144162212-Aug-18 23:54 
GeneralRe: RDP connections in tabs Pin
Pete O'Hanlon13-Aug-18 0:27
mvePete O'Hanlon13-Aug-18 0:27 
GeneralRe: RDP connections in tabs Pin
Member 1144162213-Aug-18 1:17
Member 1144162213-Aug-18 1:17 
GeneralRe: RDP connections in tabs Pin
Pete O'Hanlon13-Aug-18 1:23
mvePete O'Hanlon13-Aug-18 1:23 
GeneralRe: RDP connections in tabs Pin
Mycroft Holmes13-Aug-18 2:16
professionalMycroft Holmes13-Aug-18 2:16 
GeneralRe: RDP connections in tabs Pin
Member 1144162213-Aug-18 3:10
Member 1144162213-Aug-18 3:10 
GeneralRe: RDP connections in tabs Pin
Mycroft Holmes13-Aug-18 13:28
professionalMycroft Holmes13-Aug-18 13:28 
QuestionClasses In Threads - Pause One Until Another Finished Pin
Kevin Marois8-Aug-18 6:43
professionalKevin Marois8-Aug-18 6:43 
AnswerRe: Classes In Threads - Pause One Until Another Finished Pin
Richard Deeming8-Aug-18 8:05
mveRichard Deeming8-Aug-18 8:05 
Something like this should work:
C#
public class Test1 : ITest
{
    private readonly ManualResetEventSlim _mre;
    
    public Test1(ManualResetEventSlim mre)
    {
        _mre = mre;
    }
    
    public TestResult PerformTest()
    {
        try
        {
            Thread.Sleep(60 * 10 * 1000);
            return TestResult.Failed;
        }
        finally
        {
            _mre.Set();
        }
    }
}

public class Test2 : ITest
{
    private readonly ManualResetEventSlim _mre;
    
    public Test2(ManualResetEventSlim mre)
    {
        _mre = mre;
    }
    
    public TestResult PerformTest()
    {
        Thread.Sleep(60 * 2 * 1000);
        
        // Wait for Test1 to complete:
        _mre.Wait();

        // Do some other stuff here.
        return TestResult.Passed;
    }
}

static class Program
{
    static void Main()
    {
        var mre = new ManualResetEventSlim();
        
        var tests = new List<ITest>
        {
            new Test1(mre),
            new Test2(mre),
        };
        
        var tasks = new List<Task>();
        foreach (ITest test in tests)
        {
            Task task = Task.Run(() => test.PerformTest());
            tasks.Add(task);
        }
        
        Task.WaitAll(tasks.ToArray());
    }
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

AnswerRe: Classes In Threads - Pause One Until Another Finished Pin
OriginalGriff8-Aug-18 8:09
mveOriginalGriff8-Aug-18 8:09 
GeneralRe: Classes In Threads - Pause One Until Another Finished Pin
Kevin Marois8-Aug-18 8:22
professionalKevin Marois8-Aug-18 8:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.