コード例 #1
0
            private async Task <RemoteHostClient.Session> TryGetSessionAsync()
            {
                using (await _gate.DisposableWaitAsync(_cancellationToken).ConfigureAwait(false))
                {
                    if (_sessionDoNotAccessDirectly != null)
                    {
                        return(_sessionDoNotAccessDirectly);
                    }

                    if (_client == null)
                    {
                        // client can be null if host is shutting down
                        return(null);
                    }

                    // We create a single session and use it for the entire lifetime of this process.
                    // That single session will be used to do all communication with the remote process.
                    // This is because each session will cause a new instance of the RemoteSymbolSearchUpdateEngine
                    // to be created on the remote side.  We only want one instance of that type.  The
                    // alternative is to make that type static variable on the remote side.  But that's
                    // much less clean and would make some of the state management much more complex.
                    _sessionDoNotAccessDirectly = await _client.TryCreateServiceSessionAsync(
                        WellKnownServiceHubServices.RemoteSymbolSearchUpdateEngine,
                        _logService,
                        _cancellationToken).ConfigureAwait(false);

                    return(_sessionDoNotAccessDirectly);
                }
            }