I have an application that will make simultaneous downloads of different data sources. In it I have DataGridView
that will receive the result
of a select and from the quantity of lines that come from that result
I will have the same amount of TabPages
. Each TabPage
will have a Textbox
to record the progress of the downloads. Downloads are done in periods, which are also variable, depending on the download setting. That said, I have the following situation ... As every time I run the query, I mount new objects and even create Timer
and BackgroundWorker
to perform all actions.
To avoid creating too many tabs, I'm traversing TabControl
in a foreach and using TabPage.Dispose()
to free up application resources. I just could not find a way to do the same with Timer
and BackgroundWorker
. How could I find the two to "kill" them at runtime?
Update: Object creation code
private void createLogColTab(int pCodigoCol,
string pTipoCol)
{
TabPage tbpNew = new TabPage();
tbpNew.Tag = pCodigoCol.ToString();
tbpNew.Name = "tbpLogCol" + clsGeneric.TruncateLongString(pCodigoCol.ToString(), 3, "R", "0");
tbpNew.Text = pTipoCol;
tbpNew.Height = panel1.Height;
tbpNew.Width = panel1.Width;
TextBox txtResult = new TextBox();
txtResult.Name = "txtLogCol" + clsGeneric.TruncateLongString(pCodigoCol.ToString(), 3, "R", "0");
txtResult.Multiline = true;
txtResult.Height = tbpNew.Height;
txtResult.Width = tbpNew.Width;
txtResult.Text = tbpNew.Name;
txtResult.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top);
txtResult.Tag = pCodigoCol.ToString();
Timer tmrNew = new Timer();
tmrNew.Tag = pCodigoCol.ToString();
BackgroundWorker bgwNew = new BackgroundWorker();
bgwNew.WorkerReportsProgress = true;
bgwNew.DoWork += bgwMain_DoWork;
bgwNew.ProgressChanged += bgwMain_ProgressChanged;
bgwNew.RunWorkerCompleted += bgwMain_RunWorkerCompleted;
tbcLogColeta.TabPages.Add(tbpNew);
}