1

I am having trouble using a BackgroundWorker that calls a method in a third party COM Interop wrapper. The COM methods run for a while and I need to provide feedback to the UI. The COM methods do provide a callback that I can use.

I call my method as so;

VariableUpdater updater = new VariableUpdater(variablesToUpdate);
updater.ProcessFiles();

And in ProcessFiles I launch my backgroundworker;

public void ProcessFiles()
{
    m_worker.RunWorkerAsync();
}  

Which does;

private void m_worker_DoWork(object sender, DoWorkEventArgs e)
{   
    UpdateVariables();    
}

public bool UpdateVariables()
{
    IEdmBatchUpdate2 update = this.Vault.CreateUtility(EdmUtility.EdmUtil_BatchUpdate) as IEdmBatchUpdate2;
    for (int i = 0; i < foundExcelRows.Count(); i++)
    {
            // bunch of code                
            update.SetVar(importFile.FileID, variable.DestinationVarID, ref value, defaultConfig, 0);
    }
    Array errors = Array.CreateInstance(typeof(EdmBatchError), 0);
    try
    {
        update.CommitUpdate(out errors, null); // COM Call -> Crashes here
        return true;
    }
    catch (Exception ex)
    {
            log.Error("update error", ex);
        return false;
    }
}

Now here is the kicker; this all works wonderfully on Win7, Windows 2008 R2, and Windows 2k12. It crashes with c0000374 only on Win2k8, both SP1 and SP2. The code runs fine if I create and call IEmdBatchUpdate2.CommitUpdate() from the UI thread.

I have also tried to no avail;

Thread asyncThread = new Thread(new ThreadStart(updater.ProcessFiles));
asyncThread.SetApartmentState(ApartmentState.STA);
asyncThread.Start();

I have been stuck on this for a couple of days and before I add another process that does the update, I was wondering if anyone had any ideas.

Here's the error;

Problem Event Name: APPCRASH
Application Name:   CEMigrationTool.exe
Application Version:    1.5.1.2
Application Timestamp:  531933ad
Fault Module Name:  StackHash_2d26
Fault Module Version:   6.0.6002.18881
Fault Module Timestamp: 51da3e00
Exception Code: c0000374
Exception Offset:   000abc4f
OS Version: 6.0.6002.2.2.0.272.7
Locale ID:  1033
ehcanadian
  • 1,738
  • 1
  • 15
  • 23
  • The error code `c0000374` is usually an indication of **heap corruption**. Could it be a buggy third party lib? – Baldrick Mar 07 '14 at 02:51
  • More than likely it is. I don't know how to handle the situation though. – ehcanadian Mar 07 '14 at 14:18
  • Contact that 3rd party of course, they are the ones that have the knowledge and tools to do something about it. Send them a small repro project that demonstrates the issue. Meanwhile, do avoid using code that you don't know to be thread-safe on a worker thread. – Hans Passant Mar 07 '14 at 14:57
  • I think that's my only hope. Any idea why it only happens on Win2k8? I know you don't have a crystal ball but maybe there is a hotfix or something I could look for? – ehcanadian Mar 07 '14 at 15:08

1 Answers1

0

Maybe you should try catching all exceptions that can be thrown like this and attempt to retry any failed attempts:

public bool UpdateVariables()
{
    try
    {
        IEdmBatchUpdate2 update = this.Vault.CreateUtility(EdmUtility.EdmUtil_BatchUpdate) as IEdmBatchUpdate2;

        for (int i = 0; i < foundExcelRows.Count(); i++)
        {
                // bunch of code                
                update.SetVar(importFile.FileID, variable.DestinationVarID, ref value, defaultConfig, 0);
        }
        Array errors = Array.CreateInstance(typeof(EdmBatchError), 0);

        update.CommitUpdate(out errors, null); // COM Call -> Crashes here
        return true;
    }
    catch (Exception ex)
    {
            log.Error("update error", ex);
        return false;
    }
}

Edit

Also try looking at this article if you are unable to catch the exception

Preventing Exceptions from 3rd party component from crashing the entire application

Community
  • 1
  • 1
Cole W
  • 15,123
  • 6
  • 51
  • 85
  • There's nothing to catch. The crash happens and it takes the whole thing down. – ehcanadian Mar 07 '14 at 14:40
  • The application is crashing because of an uncaught exception. Catch the exception and you can possibly move on. – Cole W Mar 07 '14 at 14:53
  • The crash happens in/on update.CommitUpdate(). I wish I could catch it. I try to catch it but it's happening in the 3rd party dll so there isn't much I can do about it. :) – ehcanadian Mar 07 '14 at 15:06
  • How do you know it's happening in that function? I don't see any logging or errors that indicate that. – Cole W Mar 07 '14 at 15:08
  • When debugging it never gets past that line, and the log.Error("update error", ex) isn't called. – ehcanadian Mar 07 '14 at 15:12
  • @ehcanadian Take a look at my edit above. Have you seen that article? – Cole W Mar 07 '14 at 15:20