mkjeff / secs4net

SECS-II/HSMS-SS/GEM implementation on .NET
https://mkjeff.github.io/secs4net/
MIT License
443 stars 195 forks source link

SendAsync Not Sending In A Specific Case #89

Closed elosmany closed 1 year ago

elosmany commented 1 year ago

The if branch (using Thread.Sleep to wait for ConnectionState.Selected) works fine. The else branch (using the ConnectionChanged EventHandler instead) times out (Secs4Net.SecsException: T3 Timeout!).

await secConnector.StartAsync(cts.Token);

if (false) 
{
    Thread.Sleep(3000);
    Console.WriteLine(secConnector.State);
    var s18f10 = await secGem.SendAsync(s18f9);
    Console.WriteLine(s18f10.SecsItem[2].GetString());
}
else 
{
    var t11 =  new TaskCompletionSource<bool>();

    secConnector.ConnectionChanged +=  delegate 
    {
        Console.WriteLine(secConnector.State);
        if (secConnector.State == ConnectionState.Selected)
        {
            t11.SetResult(true);
        }
    };
    await t11.Task;
    Console.WriteLine(secConnector.State);
    var s18f10 = await secGem.SendAsync(s18f9);
    Console.WriteLine(s18f10.SecsItem[2].GetString());
}

Probably similar to #34 but the workaround mentioned not working my case.

elosmany commented 1 year ago

Not a bug. The problem occurs because I send before the LinkTest has been finished.