Пример #1
0
    /// <summary>
    /// Gets the next message from the server by repeatedly polling the message queue
    /// </summary>
    /// <returns>Message from server</returns>
    /// <throws>TaskCanceledException if task is cancelled</throws>
    private string CheckForStringMessage()
    {
        string s           = null;
        var    waitHandles = new WaitHandle[] { stringMessageQueue.eventWaiter, net.ctSource.Token.WaitHandle };

        while (!stringMessageQueue.TryDequeue(out s))
        {
            EventWaitHandle.WaitAny(waitHandles);
            net.ctSource.Token.ThrowIfCancellationRequested();
        }
        return(s);
    }
Пример #2
0
    /// <summary>
    /// Gets the next message from the server by repeatedly polling the message queue.
    /// </summary>
    /// <returns>Message from server</returns>
    /// <throws>TaskCanceledException if task is cancelled</throws>
    private ProtoMessage CheckForProtobufMessage()
    {
        ProtoMessage m           = null;
        var          waitHandles = new WaitHandle[] { protobufMessageQueue.eventWaiter, net.ctSource.Token.WaitHandle };

        while (!protobufMessageQueue.TryDequeue(out m))
        {
            EventWaitHandle.WaitAny(waitHandles);
            net.ctSource.Token.ThrowIfCancellationRequested();
        }
        return(m);
    }
Пример #3
0
    /// <summary>
    /// Gets the next message from the server by repeatedly polling the message queue.
    /// </summary>
    /// <returns>Message from server</returns>
    /// <throws>TaskCanceledException if task is cancelled</throws>
    public ProtoMessage CheckForProtobufMessage()
    {
        ProtoMessage m           = null;
        var          waitHandles = new WaitHandle[] { protobufMessageQueue.eventWaiter, net.ctSource.Token.WaitHandle };

        while (!protobufMessageQueue.TryDequeue(out m))
        {
            //net.ctSource.Cancel();

            int i = WaitHandle.WaitAny(waitHandles, 5000);
            net.ctSource.Token.ThrowIfCancellationRequested();
            if (i == 258)
            {
                Debug.Log("CheckForProtoBufMessage timed out.");
                //SceneManager.LoadScene("LogIn");
                return(null);
            }
            //Debug.Log("Timeout worked");
            //Debug.Log(i.ToString());

            //break;
        }
        return(m);
    }