override internal void HandleTimeout(Object sender, TimeoutEventArgs args)
        {
            FragmentationMessageTerminatedEventArgs messageTerminatedHandlerArgs = null;
            bool sendData = false;

#if PRINTALL
            Trace.Print("Timeout in outbound message!");
#endif

            lock (_lock)
            {
                if (!_timerEnabled)
                {
#if PRINTALL
                    Trace.Print("timer is not enabled. Do nothing.");
#endif
                    return;
                }

                _timerEnabled = false; // no need to unregister since automatically unregister when timeout is fired.
                if (_currentState == FragmentationMessageState.Disposed)
                {
                    return;
                }

                if (this != args.Message)
                {
                    throw new ArgumentException("timeout delivered with wrong message");
                }
                _nbTimeoutWithoutAck++;
                if (_nbTimeoutWithoutAck >= c_maxNbTimeoutWithoutNewMessage)
                {
                    _sendStatus   = Status.Timeout;
                    _currentState = FragmentationMessageState.SendingImpossible;

                    messageTerminatedHandlerArgs = new FragmentationMessageTerminatedEventArgs(_currentState, _sendStatus);
                }
                else
                {
                    _nbFragmentsSentWithoutAck = 0;
                    _lastFragmentSent.SetAll(false);
                    _maxFragmentsBeforeAck /= 2;
                    if (_maxFragmentsBeforeAck == 0)
                    {
                        _maxFragmentsBeforeAck = 1;
                    }

                    _timeoutForResending = (2 * _timeoutForResending);
                    if (_timeoutForResending > c_maxTimeoutForResending)
                    {
                        _timeoutForResending = c_maxTimeoutForResending;
                    }

                    sendData = true;
                }
            }

            if (messageTerminatedHandlerArgs != null)
            {
                OnFragmentationMessageTerminated(messageTerminatedHandlerArgs);
            }
            else if (sendData)
            {
                SendNextDataFragment(true);
            }
        }
 /// <summary>
 /// Switch to next state after receiving a timeout
 /// </summary>
 internal abstract void HandleTimeout(Object sender, TimeoutEventArgs args);
 /// <summary>
 /// Switch to next state after receiving a timeout
 /// </summary>
 internal abstract void HandleTimeout(Object sender, TimeoutEventArgs args);
        override internal void HandleTimeout(Object sender, TimeoutEventArgs args)
        {
            FragmentationMessageTerminatedEventArgs messageTerminatedHandlerArgs = null;
            bool sendData = false;
#if PRINTALL
            Trace.Print("Timeout in outbound message!");
#endif

            lock (_lock)
            {
                if (!_timerEnabled)
                {
#if PRINTALL
                    Trace.Print("timer is not enabled. Do nothing.");
#endif
                    return;
                }

                _timerEnabled = false; // no need to unregister since automatically unregister when timeout is fired.
                if (_currentState == FragmentationMessageState.Disposed)
                {
                    return;
                }

                if (this != args.Message)
                    throw new ArgumentException("timeout delivered with wrong message");
                _nbTimeoutWithoutAck++;
                if (_nbTimeoutWithoutAck >= c_maxNbTimeoutWithoutNewMessage)
                {
                    _sendStatus = Status.Timeout;
                    _currentState = FragmentationMessageState.SendingImpossible;

                    messageTerminatedHandlerArgs = new FragmentationMessageTerminatedEventArgs(_currentState, _sendStatus);
                }
                else
                {
                    _nbFragmentsSentWithoutAck = 0;
                    _lastFragmentSent.SetAll(false);
                    _maxFragmentsBeforeAck /= 2;
                    if (_maxFragmentsBeforeAck == 0)
                    {
                        _maxFragmentsBeforeAck = 1;
                    }

                    _timeoutForResending = (2 * _timeoutForResending);
                    if (_timeoutForResending > c_maxTimeoutForResending)
                    {
                        _timeoutForResending = c_maxTimeoutForResending;
                    }

                    sendData = true;
                }
            }

            if (messageTerminatedHandlerArgs != null)
            {
                OnFragmentationMessageTerminated(messageTerminatedHandlerArgs);
            }
            else if (sendData)
            {
                SendNextDataFragment(true);
            }
        }
        override internal void HandleTimeout(Object sender, TimeoutEventArgs args)
        {
            bool sendAck = false;

            lock (_lock)
            {
                if (this != args.Message)
                    throw new ArgumentException("timeout delivered with wrong message");

                if (_currentState == FragmentationMessageState.Disposed)
                {
                    return;
                }

                if (_currentState == FragmentationMessageState.WaitingTimeoutBeforeResending)
                {
                    sendAck = true;
                }
            }

            if (sendAck) { SendAcknowledgement(); }
        }