Exemplo n.º 1
0
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            var quitConfirm = XtraMessageBox.Show("Quit ??", "Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (quitConfirm == DialogResult.Cancel)
            {
                e.Cancel = true;
            }
            else
            {
                StaticHomeModule.KillProcessByName("BvSsh");
            }
        }
Exemplo n.º 2
0
        public async Task CheckBalanceAsyn(InfoRequired info)
        {
            StaticHomeModule.KillProcessByName("BvSsh");
            _taskManagers.Clear();
            cancelSources.Clear();

            AddTaskManager(info);
            var keyBag    = new ConcurrentBag <BtcKeys>(info.keys);
            var sshBag    = RenewSsh(info.SshFileSelected);
            var temKeyBag = keyBag.Count;

            temSshCount = StaticSsh.LoadListSshFromFile(info.SshFileSelected).Count;

            listKeyHaveMoney = new List <WithBalanceToSave>();
            listEmptyBalance = new List <EmptyBalanceToSave>();
            listErrorKey     = new List <ErrorKeyToSave>();
            await Task.Run(async() =>
            {
                int taskCancel = 0;
                var tasks      = new List <Task>();
                for (int i = 1; i <= info.Thread; i++)
                {
                    var _cancelSource = new CancellationTokenSource();
                    int taskId        = i;
                    Thread.Sleep(20);
                    var t = Task.Run(() =>
                    {
                        var temTask = taskId;
                        var manager = GetTaskManager(taskId);
                        try
                        {
                            manager.ChangeIp(sshBag);
                            OnProxyUsed(new ProxyUsedEventArg()
                            {
                                ProxyUsed = temSshCount - sshBag.Count,
                            });
                            while (!keyBag.IsEmpty) // >>>>>>>>>>
                            {
                                _cancelSource.Token.ThrowIfCancellationRequested();

                                OnKeyQueue(new KeyQueueEventArgs()
                                {
                                    KeyQueue = keyBag.Count,
                                });
                                OnKeyChecked(new KeyCheckedEventArgs()
                                {
                                    KeyChecked = temKeyBag - keyBag.Count,
                                });
                                if (keyBag.TryTake(out BtcKeys key))
                                {
                                    lock (o) { GetKeybalanceInfo(key, manager, sshBag, temSshCount); }
                                }
                            }
                        }
                        catch (OperationCanceledException)
                        {
                            taskCancel++;
                            OnTaskStop(new TaskStopEventArg()
                            {
                                ThreadNumber = taskCancel,
                                StopReason   = $"Stop Thread: "
                            });
                        }
                    }, _cancelSource.Token);
                    cancelSources.Add(_cancelSource);
                    tasks.Add(t);
                }
                await Task.WhenAll(tasks);
                if (taskCancel == info.Thread)
                {
                    return;
                }
                tasks.Clear();
                cancelSources.Clear();
            });
        }