Monday, March 05, 2018

longrunning c# Task mit Fehlerbehandlung

                var t = new Task(() => { ImportFile(tablename, conStr, ofd.FileName); },TaskCreationOptions.LongRunning);
                var nextTask = t.ContinueWith(antecedent =>
                {
                    if (antecedent.IsFaulted)
                    {
                        PLog.ShowAndLogError("SqlTools.ImportFile Error: " + antecedent?.Exception?.Message +antecedent?.Exception?.InnerException?.Message);
                    }
                    else if (antecedent.IsCanceled)
                    {
                        PLog.LogWarning("SqlTools.ImportFile Canceled: ");
                    }
                    else
                    {
                        PLog.LogInfo("SqlTools.ImportFile succeeded ! ");
                    }
                });
                t.Start();

No comments: