コード例 #1
0
 private void dataGridViewPositions_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (PositionsGrid.SelectedRows[0].Cells["ticker"].Value != null)
         {
             string      ticker        = PositionsGrid.SelectedRows[0].Cells["ticker"].Value.ToString();
             Stock       selectedStock = stocks.ToList().Find(s => s.Ticker == ticker);
             HoldingForm form          = new HoldingForm(refreshTime, selectedStock);
             form.ShowDialog();
             if (form.stock != null)
             {
                 stocks[stocks.ToList().FindIndex(s => s.Ticker == form.stock.Ticker)] = form.stock;
             }
             UpdateGrids();
         }
     }
     catch
     {
     }
 }
コード例 #2
0
ファイル: BatchUrlChecker.cs プロジェクト: PersonalityPi/Test
        private void StartBatchUrlCheck(ThreadedBindingList <MarketPlaceContent> boundList, SynchronizationContext threadToInvoke, DoWorkEventArgs e, BackgroundWorker worker)
        {
            int progressbarMax = 100;

            bgw.ReportProgress(0);
            if (NetworkDelay == 0)
            {
                bgw.ReportProgress(progressbarMax);
                return;
            }
            try
            {
                List <MarketPlaceContent> workingContent = boundList.ToList();

                foreach (MarketPlaceContent oneContent in workingContent)
                {                               //e.argument is ForceRecheck true/false
                    int     DelayModifier = 40; //todo Math Over here, Fill progress bar with correct value
                    int     Delay         = 1000 / DelayModifier;
                    decimal InnerCount;
                    decimal OuterCount      = workingContent.IndexOf(oneContent) + 1;
                    int     InnerTotal      = DelayModifier * Delay * NetworkDelay;
                    int     OuterTotal      = workingContent.Count;
                    int     ProgressPercent = (int)Math.Ceiling(OuterCount / OuterTotal * progressbarMax);



                    if (worker.CancellationPending && !(bool)e.Argument)
                    {
                        break;
                    }
                    if (!oneContent.DownloadChecked || (bool)e.Argument)
                    {
                        oneContent.CheckDownloadUrl(worker.CancellationPending, (bool)e.Argument);
                    }
                    else
                    {
                        bgw.ReportProgress(ProgressPercent);
                        continue;
                    }
                    var elementAtOrDefault = boundList.ElementAtOrDefault(workingContent.IndexOf(oneContent));
                    if (elementAtOrDefault != null && elementAtOrDefault.TitleId == oneContent.TitleId)
                    {
                        //boundList.RaiseListChangedEvents = false;
                        boundList[workingContent.IndexOf(oneContent)] = oneContent;
                        //boundList.RaiseListChangedEvents = true;
                        //threadToInvoke.Post(delegate { boundList.ResetItem(boundList.IndexOf(oneContent)); }, null);
                    }
                    bgw.ReportProgress(ProgressPercent);
                    //networkdelay * 10 * sleep = TotalDelay
                    if (oneContent.DownloadChecked || (bool)e.Argument)
                    {
                        if (!(workingContent.IndexOf(oneContent) >= workingContent.Count)) //Skip the Delay
                        {
                            //NetworkDelay is Delay as Int Value in Seconds
                            for (int i = 0; i < NetworkDelay * DelayModifier; i++)
                            {
                                InnerCount = Delay * i;

                                ProgressPercent = (int)Math.Ceiling((InnerCount + OuterCount * InnerTotal) / (InnerTotal * (OuterTotal + 1)) * progressbarMax);


                                bgw.ReportProgress(ProgressPercent);
                                if (worker.CancellationPending)
                                {
                                    break;
                                }
                                Thread.Sleep(Delay);
                            }
                            if (worker.CancellationPending)
                            {
                                break;
                            }
                        }
                        else
                        {
                            ProgressPercent = (int)Math.Ceiling((OuterCount + 1 / OuterTotal) * progressbarMax);
                        }
                    }
                }
            }
            catch (InvalidOperationException ex)
            {
                boundList.ResetBindings();
                //Do Nothing Here, This Exception Is Intentional
                //And is Caused by allcontent being changed from user switching the page they are viewing
                Console.WriteLine(e.ToString());
                throw;
            }
        }