function CEL_OnLineTimeChanged(Source, EventID, time, varargin)

global m_CEL;

global m_CurFunc;

global m_Status;

global m_UpdatesCount;
global m_LatencyTime;
global m_PlacedOrdersCount;

try
    m_LatencyTime = m_LatencyTime + 1;
    
    timedOut = false;
    
    switch m_CurFunc
        
        case 'none'
            QueryFunctions;
            
        case 'realtimedata'
            % Cancelling order if it wasn't filled within 10 seconds.
            if ~strcmp(m_CEL.Environment.get('GWConnectionStatus'), 'csConnectionUp') || m_PlacedOrdersCount > 0
                QueryFunctions;
            elseif m_UpdatesCount > 5
                timedOut = true;
            else
                m_UpdatesCount = m_UpdatesCount + 1;
            end

        case 'timedbars'
            if m_Status > 2
                QueryFunctions;
            elseif m_Status == 0 && m_LatencyTime > 15
                timedOut = true;
            end
            
        otherwise
            if m_UpdatesCount == 0 && m_LatencyTime > 15
                timedOut = true;
            elseif m_UpdatesCount > 5 || m_LatencyTime > 300
                QueryFunctions;
            end
    
    end
    
    if timedOut
        switch m_CurFunc
            case 'orders'
                disp('Expression request is timed out.');
                
            case 'realtimedata'
                disp('Order placing is timed out.');
                
            case 'timedbars'
                disp('Real time data request is timed out.');
                
            case ''
                disp('Timed bars request is timed out.');
        end
        QueryFunctions;
    end
catch
    CEL_ShutDown;
    disp('An error occurred in CEL_OnLineTimeChanged.m file.');
end