Wednesday, November 12, 2008

Google templates

In a recent past life I wrote business plans for competitions held amongst Washington universities. I converted one of my winning plans to a Google Template and donated it to the Google templates team.



Given how sad the economic market is looking, it might be a great time to sit down and write down that idea you have been mulling over for years. You just don't know when you might need to find new employment.

Sunday, November 9, 2008

OpenFileDialog.showDialog hangs on Vista

OpenFileDialog began hanging when called directly from some of my code. (I'm dealing with C# 2.0 here.)

Turns out it doesn't run in it's own thread, but takes over your main thread. Vista just isn't a big fan of this. To get around it you need to invoke OpenFileDialog from within another thread. I stumbled upon this code that will work nice any time you need to popup another dialog window (such as a process indicator or built in ones like OpenFileDialog). Hopefully our pals over in Redmond fix up OpenFileDialog to just do this by default in the future.

I stumbled upon this code out in the blogosphere (https://forums.microsoft.com) awhile ago.

public class Invoker
{
public OpenFileDialog InvokeDialog;
private Thread InvokeThread;
private DialogResult InvokeResult;

public Invoker()
{
InvokeDialog = new OpenFileDialog();
InvokeThread = new Thread(new ThreadStart(InvokeMethod));
InvokeThread.SetApartmentState(ApartmentState.STA);
InvokeResult = DialogResult.None;
}

public DialogResult Invoke()
{
InvokeThread.Start();
InvokeThread.Join();
return InvokeResult;
}

private void InvokeMethod()
{
InvokeResult = InvokeDialog.ShowDialog();
}
}

Usage :

Invoker I = new Invoker();

if (I.Invoke() == DialogResult.OK)
{
MessageBox.Show(I.InvokeDialog.FileName, "Test Successful.");
}
else
{
MessageBox.Show("Test Failed.");
}