Further along in this code I'm trying to access processRow, which is of type DataRow, but I get a RowNotInTableException This row has been removed from a table and does not have any data.

In an attempt to figure out when this data is getting deleted, I added a bunch of cq_id = processRow["cq_id"].ToString(); throughout. See code below for where it's breaking. I also discovered that if I get rid of the Task, this error goes away, but I need that.

I can't figure out why I'm getting such an exception as nowhere in the code am I deleting anything. I'm assuming it has something to do with the task.

string srcFile = processRow["u_filepath"].ToString() + "\\" + processRow["u_filename"].ToString();

Task task = Task.Factory.StartNew(() =>
{                    
    string file, directory;

    try   // copy powerpoint presentation to local directory
    {
        invokeLogging("Copying file " + srcFile + " to " + localDirectory + "....");
        file = RSNAPresentation.Converter.CopyFile(srcFile, localDirectory);
        directory = Path.GetDirectoryName(file);

    try
    {
        ConverterData converterData = null;

        invokeLogging("Opening presentation " + file + "....");

        // this line works
        string cq_id = processRow["cq_id"].ToString();

        using (RSNAInterop interop = new RSNAInterop(file))
        {
           // this line throws exception
           cq_id = processRow["cq_id"].ToString();

          // more code...........



public RSNAInterop(string pptfile)
{
    try
    {
        killPTT();
    }
    catch (Exception ex)
    {

    }

    try
    {
       this.appPpt = new Microsoft.Office.Interop.PowerPoint.Application();
       this.appPpt.Visible = Microsoft.Office.Core.MsoTriState.msoCTrue;
       this.objActivePresentation = appPpt.Presentations.Open(pptfile, Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue);

       logger.Log(LogLevel.Info, "Opened " + pptfile);
    }
    catch (Exception e)
    {
       logger.Log(LogLevel.Error, e.Message);
       logger.Log(LogLevel.Error, e.StackTrace);

       this.Dispose();
       throw;
    }


public static void killPTT()
{
    Process[] processes = Process.GetProcessesByName("POWERPNT");

    foreach (Process process in processes)
    {
        process.Kill();
        Thread.Sleep(1000);
        if (process.HasExited == false)
        {
            process.Kill();
        }
   }
}

As a general rule, when you think about tasks, you must think about isolated processes, having thier local data, connections, and results, all of them running asinchronously from the main thread, and avoiding possible collisions.

Can you isolate the offending row inside the task?

Hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.