1

I created a WCF service using Visual Studio 2017 Community version (employing TAP). I used the AsyncAutoResetEvent from the Microsoft.VisualStudio.Threading reference but it seems that this waithandle is not getting signalled after calling the Set function. The service is hosted in a console application. The traces generated by the NonBlockingConsole.WriteLine display properly however.

server:

AsyncAutoResetEvent aare = new AsyncAutoResetEvent(false);
public async Task<string> TestfuncAsync()
{
    string strRet = "finished";
    NonBlockingConsole.WriteLine("before autoresetevent");
    await aare.WaitAsync();
    NonBlockingConsole.WriteLine("after autoresetevent");  //is not traced even if asyncautoresetevent is set
    return strRet;
}

void SetEvent()
{
    aare.Set();
    NonBlockingConsole.WriteLine("auto reset event set");
}

client UI:

private async void button1_Click(object sender, EventArgs e)
{
    string value = await client.TestfuncAsync();
    ...
}

private void button2_Click(object sender, EventArgs e)
{
    client.SetEvent();
}

NonBlockingConsole class: (reused from Does Console.WriteLine block?)

public static class NonBlockingConsole
{
    private static BlockingCollection<string> m_Queue = new BlockingCollection<string>();
    static NonBlockingConsole()
    {
        var thread = new Thread(
            () =>
            {
                while (true) Console.WriteLine(m_Queue.Take());
            }
            );
        thread.IsBackground = true;
        thread.Start();
    }
    public static void WriteLine(string value)
    {
        value = DateTime.Now.ToString("<HH:mm:ss.fff>") + " " + value + " <ThreadID>: " + Thread.CurrentThread.ManagedThreadId.ToString();
        m_Queue.Add(value);
    }
}
eyesT
  • 11
  • 2
  • How did you configure your WCF contract? – Jeroen Heier Aug 24 '18 at 15:32
  • @Jeroen Sorry for the late reply. Just came back from a holiday. No special configuration as shown below: [OperationContract] Task TestfuncAsync(); [OperationContract] void SetEvent(); – eyesT Aug 28 '18 at 06:38

0 Answers0