Grpc.Core.GrpcEnvironment.AddRef C# (CSharp) Method

AddRef() static private method

Returns a reference-counted instance of initialized gRPC environment. Subsequent invocations return the same instance unless reference count has dropped to zero previously.
static private AddRef ( ) : GrpcEnvironment
return GrpcEnvironment
        internal static GrpcEnvironment AddRef()
        {
            ShutdownHooks.Register();

            lock (staticLock)
            {
                refCount++;
                if (instance == null)
                {
                    instance = new GrpcEnvironment();
                }
                return instance;
            }
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Creates a channel that connects to a specific host.
        /// Port will default to 80 for an unsecure channel and to 443 for a secure channel.
        /// </summary>
        /// <param name="target">Target of the channel.</param>
        /// <param name="credentials">Credentials to secure the channel.</param>
        /// <param name="options">Channel options.</param>
        public Channel(string target, ChannelCredentials credentials, IEnumerable <ChannelOption> options)
        {
            this.target  = GrpcPreconditions.CheckNotNull(target, "target");
            this.options = CreateOptionsDictionary(options);
            EnsureUserAgentChannelOption(this.options);
            this.environment = GrpcEnvironment.AddRef();

            this.completionQueue = this.environment.PickCompletionQueue();
            using (var nativeCredentials = credentials.ToNativeCredentials())
                using (var nativeChannelArgs = ChannelOptions.CreateChannelArgs(this.options.Values))
                {
                    if (nativeCredentials != null)
                    {
                        this.handle = ChannelSafeHandle.CreateSecure(nativeCredentials, target, nativeChannelArgs);
                    }
                    else
                    {
                        this.handle = ChannelSafeHandle.CreateInsecure(target, nativeChannelArgs);
                    }
                }
            // TODO(jtattermusch): Workaround for https://github.com/GoogleCloudPlatform/google-cloud-dotnet/issues/822.
            // Remove once retries are supported in C core
            this.connectivityWatcherTask = RunConnectivityWatcherAsync();
            GrpcEnvironment.RegisterChannel(this);
        }
All Usage Examples Of Grpc.Core.GrpcEnvironment::AddRef