STDAPI CPropertyMonitorTextService::Deactivate()
{
    //
    // Unadvise TextEditSink if it is advised.
    //
    _InitTextEditSink(NULL);

    //
    // Uninitialize ThreadMgrEventSink.
    //
    _UninitThreadMgrEventSink();

    //
    // Uninitialize Language Bar.
    //
    _UninitLanguageBar();

    //
    // Uninitialize thread focus sink.
    //
    _UninitThreadFocusSink();

    if (_pPopupWindow != NULL)
    {
        delete _pPopupWindow;
        _pPopupWindow = NULL;
    }

    if (_pMemStream != NULL)
    {
        _pMemStream->Release();
        _pMemStream = NULL;
    }

    if (_pDisplayAttributeMgr != NULL)
    {
        _pDisplayAttributeMgr->Release();
        _pDisplayAttributeMgr = NULL;
    }

    if (_pCategoryMgr != NULL)
    {
        _pCategoryMgr->Release();
        _pCategoryMgr = NULL;
    }

    // we MUST release all refs to _pThreadMgr in Deactivate
    if (_pThreadMgr != NULL)
    {
        _pThreadMgr->Release();
        _pThreadMgr = NULL;
    }

    _tfClientId = TF_CLIENTID_NULL;

    return S_OK;
}
STDAPI CTextService::Deactivate()
{
	if(_pThreadMgr == nullptr)
	{
		return S_OK;
	}

	_SaveUserDic();

	_EndCandidateList();

	_EndInputModeWindow();

	_UninitFunctionProvider();

	_UninitPreservedKey(0);
	_UninitPreservedKey(1);

	_UninitKeyEventSink();

	_UninitLanguageBar();

	_InitTextEditSink(nullptr);

	_UninitCompartmentEventSink();

	_UninitThreadFocusSink();

	_UninitThreadMgrEventSink();

	_UninitD2D();

	SafeRelease(&_pThreadMgr);

	_ClientId = TF_CLIENTID_NULL;

	return S_OK;
}