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