sessionrefreshthread.cs

来自「ICE3.3.0--聊天程序服务器端demo」· CS 代码 · 共 75 行

CS
75
字号
// **********************************************************************
//
// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
//
// This copy of Chat Demo is licensed to you under the terms
// described in the CHAT_DEMO_LICENSE file included in this
// distribution.
//
// **********************************************************************

using System;
using System.Threading;
using System.Windows.Threading;

namespace ChatDemoGUI
{
    //
    // This class is responsible for refreshing maintaing the
    // Glacier2 session. Instead of extending IceUtil::Thread, we
    // launch it using the ThreadStart facility.
    //
    public class SessionRefreshThread
    {
        public SessionRefreshThread(Chat.ChatSessionPrx session, long period)
        {
            this._done = false;
            this._session = session;
            this._period = period;
            _coordinator = ((App)System.Windows.Application.Current).getCoordinator();
        }

        public void run()
        {
            lock(this)
            {
                do
                {
                    try
                    {
                        _session.ice_ping();
                    }
                    catch(Ice.LocalException ex)
                    {
                    _coordinator.setError("<system-message> - The connection with the server was unexpectedly lost.\n" + ex.ToString() +
                         "\nYou can try login again from the File menu.");
                        _done = true;
                    }
                    if(!_done)
                    {
                        Monitor.Wait(this, (int)_period);
                    }
                } 
                while(!_done);
            }
        }

        public void done()
        {
            lock(this)
            {
                if(!_done)
                {
                    _done = true;
                    Monitor.PulseAll(this);
                }
            }
        }

        private Boolean _done = false;
        private Chat.ChatSessionPrx _session = null;
        private long _period;
        private Coordinator _coordinator = null;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?