0

Not sure whether there is anything wrong with this piece of code. this was running fine, but now the MethodInvoker not invoking method.

void meterReader_OnMeterReadSuccessful(MeterData MeterData,List<MeterParameters> DownloadList)
{
    if (this.InvokeRequired)

        this.Invoke(new MethodInvoker(() =>
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                Task.Factory.StartNew(new Action(() =>
                {
                    if (this.SaveMeterData.AddMeterData(MeterData, DownloadList)) this.OnDownloadSuccessful(this.SaveMeterData.MeterDataID);
                    else this.OnDataSaveFailed(this.SaveMeterData.MeterDataID);
                }));
                this.Cursor = Cursors.Default;
                this.Close();
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message); }
        }));
    }
}

What could be the possible reason?

Kirill Shlenskiy
  • 9,367
  • 27
  • 39
Sonal
  • 55
  • 1
  • 6
  • Please tag the question with the language or framework you are using. Such as C#, .Net etc. – Nisarg Shah Oct 05 '17 at 05:49
  • The if statement is executed asynchronously and could still be running when Close is called. Is this intentionally or should the UI thread wait for the if statement to complete? – Emond Oct 05 '17 at 05:52

0 Answers0