Esempio n. 1
0
        private static void CloseNTMiner()
        {
            bool         isClosed = false;
            ResponseBase response = RpcRoot.Post <ResponseBase>(NTKeyword.Localhost, NTKeyword.MinerClientPort, _minerClientControllerName, nameof(IMinerClientController.CloseNTMiner), new SignRequest {
            });

            isClosed = response.IsSuccess();
            if (!isClosed)
            {
                try {
                    string location = NTMinerRegistry.GetLocation(NTMinerAppType.MinerClient);
                    if (!string.IsNullOrEmpty(location) && File.Exists(location))
                    {
                        string processName = Path.GetFileNameWithoutExtension(location);
                        Windows.TaskKill.Kill(processName);
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 本机同步网络调用
        /// </summary>
        public void CloseMinerStudio()
        {
            string location = NTMinerRegistry.GetLocation();

            if (string.IsNullOrEmpty(location) || !File.Exists(location))
            {
                return;
            }
            string processName = Path.GetFileNameWithoutExtension(location);

            if (Process.GetProcessesByName(processName).Length == 0)
            {
                return;
            }
            bool isClosed = false;

            try {
                using (HttpClient client = RpcRoot.CreateHttpClient()) {
                    Task <HttpResponseMessage> getHttpResponse = client.PostAsJsonAsync($"http://localhost:{NTKeyword.MinerStudioPort.ToString()}/api/{_controllerName}/{nameof(IMinerStudioController.CloseMinerStudio)}", new SignRequest {
                    });
                    ResponseBase response = getHttpResponse.Result.Content.ReadAsAsync <ResponseBase>().Result;
                    isClosed = response.IsSuccess();
                }
            }
            catch (Exception e) {
                Logger.ErrorDebugLine(e);
            }
            if (!isClosed)
            {
                try {
                    Windows.TaskKill.Kill(processName, waitForExit: true);
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                }
            }
        }