Exemplo n.º 1
0
    static void ReadCallback(IAsyncResult ar)
    {
        PipeState    state  = (PipeState)ar.AsyncState;
        MyPipeClient client = state.Client;

        client.LastRead = DateTime.Now;
        int bytesRead;

        try
        {
            bytesRead = client.PipeClient.EndRead(ar);
        }
        catch (IOException)     //closed
        {
            return;
        }
        if (bytesRead > 0)
        {
            byte[] data = state.Buffer;
            //TODO: something
        }
        else     //i've never used pipes, so i'm assuming this behavior exists with them
        {
            client.Disconnect();
            return;
        }
        Read(client);
    }
Exemplo n.º 2
0
    static void TimeoutCheck(object state)
    {
        MyPipeClient client            = (MyPipeClient)state;
        TimeSpan     timeSinceLastRead = DateTime.Now - client.LastRead;

        if (timeSinceLastRead.TotalSeconds > TimeoutSeconds)
        {
            client.Disconnect();
        }
    }