I created a Word 2007 add-in project in C# that works fine on my box and a fellow developer's box. When we try to deploy the software to a blank box though, Word crashes hard (no exception thrown) when we start up a background thread.
Here's the relevant code, in the Ribbon.cs file:
private void startThread()
{
StreamWriter fout = new FileInfo("C:\\startThread.txt").CreateText();
fout.WriteLine("startThread start");
fout.Flush();
try {
ThreadStart job = new ThreadStart(this.waitForSignal);
Thread thread = new Thread(job);
thread.Start();
fout.WriteLine("No Exceptions?");
}
catch
{
fout.WriteLine("caught something");
}
fout.WriteLine("startThread end");
fout.Flush();
fout.Close();
}
public void waitForSignal()
{
StreamWriter fout = new FileInfo("C:\\waitForSignal.txt").CreateText();
fout.WriteLine("entered waitForSignal");
fout.Flush();
fout.Close();
}
startThread()
is called from the Ribbon's constructor. When run on my box, both files are created with all of the WriteLines except "caught something". When run on the other box, startThread.txt is created and all lines are output except "caught something" but waitForSignal.txt is never created and Microsoft's "there's been a problem, would you like to send an error message" box appears.
I think there is some security problem that's denying Word the ability to start new threads, but I can't figure out how I would change that.
Does anyone know if that is indeed the problem and how I would fix it? Or if you see something else that might be causing the problem?