void FillGridInsPlans()
 {
     _sortedByColumnIdx = gridInsPlans.SortedByColumnIdx;
     _isSortAscending   = gridInsPlans.SortedIsAscending;
     gridInsPlans.BeginUpdate();
     if (gridInsPlans.ListGridColumns.Count == 0)
     {
         gridInsPlans.ListGridColumns.Clear();
         gridInsPlans.ListGridColumns.Add(new UI.GridColumn("Name", 200, HorizontalAlignment.Left, UI.GridSortingStrategy.StringCompare));
         gridInsPlans.ListGridColumns.Add(new UI.GridColumn("Birthdate", 74, HorizontalAlignment.Center, UI.GridSortingStrategy.DateParse));
         gridInsPlans.ListGridColumns.Add(new UI.GridColumn("SSN", 66, HorizontalAlignment.Center, UI.GridSortingStrategy.StringCompare));
         _patNumCol = gridInsPlans.ListGridColumns.Count;
         gridInsPlans.ListGridColumns.Add(new UI.GridColumn("PatNum", 68, HorizontalAlignment.Center, UI.GridSortingStrategy.StringCompare));
         gridInsPlans.ListGridColumns.Add(new UI.GridColumn("Date Begin", 84, HorizontalAlignment.Center, UI.GridSortingStrategy.DateParse));
         gridInsPlans.ListGridColumns.Add(new UI.GridColumn("Date Term", 84, HorizontalAlignment.Center, UI.GridSortingStrategy.DateParse));
         gridInsPlans.ListGridColumns.Add(new UI.GridColumn("Relation", 70, HorizontalAlignment.Center, UI.GridSortingStrategy.StringCompare));
         gridInsPlans.ListGridColumns.Add(new UI.GridColumn("SubscriberID", 96, HorizontalAlignment.Left, UI.GridSortingStrategy.StringCompare));
         gridInsPlans.ListGridColumns.Add(new UI.GridColumn("GroupNum", 100, HorizontalAlignment.Left, UI.GridSortingStrategy.StringCompare));
         gridInsPlans.ListGridColumns.Add(new UI.GridColumn("Payer", 0, HorizontalAlignment.Left, UI.GridSortingStrategy.StringCompare));
         _sortedByColumnIdx = 0;              //Sort by Patient Last Name by default.
         _isSortAscending   = true;           //Start with A and progress to Z.
     }
     gridInsPlans.EndUpdate();
     Application.DoEvents();            //To show empty grid while the window is loading.
     if (_odThread != null)
     {
         _odThread.QuitSync(0);
     }
     _odThread = new ODThread(WorkerPreview834);
     _odThread.Start();
 }
        private void StartRefreshThread(Func <UserControlDashboardWidget, bool> funcData, string name)
        {
            ODThread previousThread = null;

            if (_threadRefresh != null && !_threadRefresh.HasQuit)
            {
                previousThread = _threadRefresh;
            }
            _threadRefresh = new ODThread((o) => {
                if (previousThread != null)
                {
                    //Allow the previous thread to finish updating its data, but quit before updating UI if it hasn't started yet.
                    previousThread.QuitSync(Timeout.Infinite);
                }
                foreach (UserControlDashboardWidget widget in ListOpenWidgets)
                {
                    if (funcData(widget))
                    {
                        if (widget.IsDisposed || !widget.IsHandleCreated)
                        {
                            continue;
                        }
                        if (!o.HasQuit)
                        {
                            widget.RefreshView();                            //Invokes back to UI thread for UI update.
                        }
                    }
                }
            });
            _threadRefresh.Name = name;
            _threadRefresh.AddExceptionHandler(ex => ex.DoNothing());            //Don't crash program on Dashboard data fetching failure.
            _threadRefresh.Start();
        }
 private void CloseWidget(UserControlDashboardWidget widget, EventArgs e)
 {
     if (widget == null)
     {
         return;
     }
     Controls.Remove(widget);
     if (ListOpenWidgets.Count == 0)
     {
         IsInitialized = false;
         _actionDashboardContentsChanged?.Invoke();
         if (!_isLoggingOff)
         {
             _actionDashboardClosing?.Invoke();
         }
         _threadRefresh?.QuitSync(100);
     }
 }
 private void FillGridInsPlanFiles()
 {
     gridInsPlanFiles.BeginUpdate();
     if (gridInsPlanFiles.ListGridColumns.Count == 0)
     {
         gridInsPlanFiles.ListGridColumns.Add(new UI.GridColumn("FileName", 300, UI.GridSortingStrategy.StringCompare));
         _colDateIndex = gridInsPlanFiles.ListGridColumns.Count;
         gridInsPlanFiles.ListGridColumns.Add(new UI.GridColumn("Date", 80, UI.GridSortingStrategy.StringCompare));
         _colPatCountIndex = gridInsPlanFiles.ListGridColumns.Count;
         gridInsPlanFiles.ListGridColumns.Add(new UI.GridColumn("PatCount", 80, UI.GridSortingStrategy.AmountParse));
         _colPlanCountIndex = gridInsPlanFiles.ListGridColumns.Count;
         gridInsPlanFiles.ListGridColumns.Add(new UI.GridColumn("PlanCount", 80, UI.GridSortingStrategy.AmountParse));
         _colErrorIndex = gridInsPlanFiles.ListGridColumns.Count;
         gridInsPlanFiles.ListGridColumns.Add(new UI.GridColumn("Errors", 0, UI.GridSortingStrategy.StringCompare));
     }
     gridInsPlanFiles.ListGridRows.Clear();
     gridInsPlanFiles.EndUpdate();
     if (!Directory.Exists(textImportPath.Text))
     {
         return;
     }
     gridInsPlanFiles.BeginUpdate();
     _arrayImportFilePaths = Directory.GetFiles(textImportPath.Text);
     for (int i = 0; i < _arrayImportFilePaths.Length; i++)
     {
         UI.GridRow row = new UI.GridRow();
         gridInsPlanFiles.ListGridRows.Add(row);
         string filePath = _arrayImportFilePaths[i];
         row.Tag = filePath;
         string fileName = Path.GetFileName(filePath);
         row.Cells.Add(fileName);          //FileName
         row.Cells.Add("");                //Date - This value will be filled in when WorkerParse834() runs below.
         row.Cells.Add("");                //PatCount - This value will be filled in when WorkerParse834() runs below.
         row.Cells.Add("");                //PlanCount - This value will be filled in when WorkerParse834() runs below.
         row.Cells.Add("Loading file..."); //Errors - This value will be filled in when WorkerParse834() runs below.
     }
     gridInsPlanFiles.EndUpdate();
     Application.DoEvents();
     if (_odThread != null)
     {
         _odThread.QuitSync(0);
     }
     _odThread = new ODThread(WorkerParse834);
     _odThread.Start();
 }