I have class (ConsoleApplication) names ClassA
with a field:
public class ClassA
{
List<Task> Tasks;
(...)
public void PlotGrid()
{
Action<object> action = new Action<object>(ShowChart);
Task task = new Task(action, intervalX);
task.Start();
Tasks.Add(task);
}
(...)
private void ShowChart(object intervalX)
{
int interval = Convert.ToInt32(intervalX);
ChartForm chart = new ChartForm(GetValuesForPlotting(), interval);
chart.ShowDialog();
}
}
(Description about ChartForm's at the end of post) Ok. When I have created the ClassA in Program.cs:
class Program
{
static void Main(string[] args)
{
ClassA class = new ClassA();
class.PlotGrid();
Console.WriteLine("it was shown as parallel with windowsform(the ChartForm)");
}
}
In terminal had shown:
it was shown as parallel with windowsform(the ChartForm) but a ChartForm not shown. I want to create a descructor
or other way for ClassA. How i can do it if a parent (ClassA) has children (ChartForm) and until it has a children whom are running - don't close app.
I tried to add in destructor ClassA:
~ClassA()
{
Task.WaitAll(Tasks.ToArray());
}
but it didn't help.
Class ChartForm
is from other project, which inherit WindowsForms (Form) and has only one object: Chart.
Please look below:
public partial class ChartForm : Form
{
private List<Complex> valuesForPlotting;
int intervalX;
public ChartForm(List<Complex> valuesForPlotting, int intervalX)
{
InitializeComponent();
this.valuesForPlotting = valuesForPlotting;
this.intervalX = intervalX;
}
private void Form1_Load(object sender, EventArgs e)
{
chart1.ChartAreas[0].AxisX.Interval = intervalX;
chart1.ChartAreas[0].AxisX.Minimum = 0;
chart1.ChartAreas[0].AxisX.Maximum = valuesForPlotting.Max(p=> p.Real)+intervalX;
for (int i = 0; i < valuesForPlotting.Count; i++)
{
chart1.Series["ser1"].Points.AddXY
(valuesForPlotting[i].Real, valuesForPlotting[i].Imaginary);
}
chart1.Series["ser1"].ChartType = SeriesChartType.FastLine;
chart1.Series["ser1"].Color = Color.Red;
}
}