PDA

View Full Version : Getting STA Error when ShowDialog from C# Custom Action



gkriggs
07-30-2008, 04:37 PM
Hello,

I created a C# WPF window I would like display with ShowDialog when the user clicks on a button during the UI Sequence. I created a simple C# method that takes nothing and returns nothing that displays the dialog. I marked this method with "[STAThread]" attribute. I created a managed custom action that calls this method when the user clicks on a button. I am getting an exception "The calling thread must be STA, because many UI components require this"

Any ideas how to fix this problem?

Thanks!
Greg

gkriggs
07-30-2008, 05:41 PM
FWIW, I figured out a workaround that seems to work okay. I create an STA thread that launches the dialog as follows:

[STAThread]
public void DisplayDialog()
{
try
{
Thread worker = new Thread(DisplayDialogInternal);
worker.SetApartmentState(ApartmentState.STA);
worker.Start();
worker.Join();
}
catch (Exception exp)
{
ExceptionUtil.DisplayError(exp);
}
}

public void DisplayDialogInternal()
{
try
{
SomeWPFWindow gui = new SomeWPFWindow();
gui.ShowDialog();
}
catch (Exception exp)
{
ExceptionUtil.DisplayError(exp);
}
}

Christopher Painter
07-30-2008, 10:37 PM
Also be sure to check out Deployment Tools Foundtion (DTF)

gkriggs
08-04-2008, 05:44 PM
Do you know of an example that shows how to use "Deployment Tools Foundtion (DTF)" from InstallShield?
Thanks,
Greg

Christopher Painter
08-04-2008, 06:19 PM
DTF packages it's CA as a standard Type1 CA so it is compatible interchangable with what InstallShield calls an "MSI DLL stored in the Binary table" custom action type.