/// <summary> /// /// </summary> /// <param name="symbol"></param> /// <param name="exchange"></param> /// <param name="dataFolder"></param> /// <param name="daysToExport"></param> /// <param name="includeCurrentDay"></param> private void ExportSecurityToFile(string symbol, string exchange, string dataFolder, int daysToExport, bool includeCurrentDay) { var exportManager = new ApiSecurityEventExportManager(symbol, exchange, daysToExport, dataFolder, includeCurrentDay); exportManager.OnProgressUpdate += exportManager_OnProgressUpdate; exportManager.Export(); }
/// <summary> /// /// </summary> /// <param name="symbol"></param> /// <param name="exchange"></param> /// <param name="dataFolder"></param> /// <param name="includeCurrentDay"></param> private void exportSecurityToFile(string symbol, string exchange, string dataFolder, bool includeCurrentDay) { //Add spacer line to progress text if already run an export btnCancel.Enabled = true; btnExport.Enabled = false; if (txtProgress.Text.Length > 0) { txtProgress.Text = "\r\n" + txtProgress.Text; } //Initiate export int daysToExport = (int)udDays.Value; _exportManager = new ApiSecurityEventExportManager(symbol, exchange, daysToExport, dataFolder, includeCurrentDay); _exportManager.OnProgressUpdate += new EventHandler <SparkAPI.Common.Events.GenericEventArgs <string> >(exportManager_OnProgressUpdate); _exportThread = new Thread(_exportManager.Export); _exportThread.Start(); //HACK: Following the initiation of the export process on a separate thread, the export form loses focus. //This means that if a user clicks 'Cancel' the first click is refocusing on the form, and the button click //is not detected. To avoid this, we force focus back on the export form to ensure the 'Cancel' click is //detected. //Focus on form so that Cancel button click is detected first click this.Focus(); //Wait until export complete or cancelled while ((_exportThread.ThreadState != ThreadState.Stopped) && (_exportThread.ThreadState != ThreadState.Aborted)) { Thread.Sleep(200); Application.DoEvents(); } btnCancel.Enabled = false; btnExport.Enabled = true; }