cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
gkriggs
Level 6

Getting STA Error when ShowDialog from C# Custom Action

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
Labels (1)
0 Kudos
(4) Replies
gkriggs
Level 6

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);
}
}
0 Kudos
Christopher_Pai
Level 16

Also be sure to check out Deployment Tools Foundtion (DTF)
0 Kudos
gkriggs
Level 6

Do you know of an example that shows how to use "Deployment Tools Foundtion (DTF)" from InstallShield?
Thanks,
Greg
0 Kudos
Christopher_Pai
Level 16

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.
0 Kudos