async/await, no results
-
I thought I'd read about async/await as I'd said, and that's what it was.
On the basis of several examples, the code block was completed
static Task<double> getresulting(int frc,int frc1,double shag,double U,double T) { int t = 0; double resulting = 0; NumericalIntegration integration = new NumericalIntegration(); return Task.Run(() => {
resulting = (1 / (2 * Math.PI)) * integration.Calculate(angularFrequency => GetSpectralDensityOfAmplitude(GetSpectralDensity(U, angularFrequency, T)) * Math.Cos(angularFrequency * t), 0, frc1); return resulting; }); }
Then the method from which I've been slowing it all down has made it async-method.
And I will.static Task<double> getresulting
In the line
double resulting = await getresulting(frc, frc1, shag, U, T);
I do what I'm supposed to do.
public async void drawreverse(double U, double T, double shag, int frc, int frc1)
{
GraphPane panel77 = zedGraphControl2.GraphPane;
//NumericalIntegration integration = new NumericalIntegration();
//double t = 0;
panel77.Title.Text = "Обратное преобразование";
panel77.XAxis.MajorGrid.IsVisible = true;
panel77.YAxis.MajorGrid.IsVisible = true;
panel77.YAxis.MajorGrid.IsZeroLine = false;
panel77.XAxis.Title.Text = "f,кГЦ";
panel77.YAxis.Title.Text = "U(f), мВ*с";
PointPairList list1 = new PointPairList();for (double fr = frc; fr <= frc1; fr += shag) { double resulting = await getresulting(frc, frc1, shag, U, T); list1.Add(fr, resulting); } panel77.AddCurve("", list1, Color.Blue, SymbolType.None); panel77.XAxis.Scale.Min = xmin_limit; panel77.XAxis.Scale.Max = xmax_limit; panel77.YAxis.Scale.Min = ymin_limit; panel77.YAxis.Scale.Max = ymax_limit; zedGraphControl2.AxisChange(); zedGraphControl2.Invalidate(); }
The program is compiled and operated, but it doesn't work on ZedGraphControl2.
I don't clean it because it's filled with points, and I assumed I'd call task getresulting at every step and put a point at the coordinates.
-
The problem is you don't get anything between the calculation of the parts. You've got one point of result that's going to come into.
list1
♪ And only after all the work is donelist1
It's a schedule. If you want to be updated after each counted point, add the data tozedGraphControl2
after each cycle iteration.