Saturday, 24 August 2013

C# calling form.show() from another thread is not working in setup

C# calling form.show() from another thread is not working in setup

In my c# windows application, I want to show a form by a thread which is
already called by another thread. The code I am using for this is as
below:
private void ThreadFirst()
{
// Do some work...
// Calling second thread from this.
var thread = new Thread(ThreadSecond);
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
private void ThreadSecond()
{
StartGetUserAuthenticationDetail();
//Do some work...
}
[STAThread]
private void StartGetUserAuthenticationDetail()
{
try
{
//Do some work...
// Open this form in case of Delayed upload
//Application.DoEvents();
globalForm = new myForm();
globalForm.Show();
Close();
ShowInTaskbar = false;
Application.Run();
}
catch (Exception ex)
{
messagebox.Show(ex.message);
}
}
It is working perfect when I am running this from my solution. But, when I
am creating a msi package for this, both of the forms got hide. Am I
missing something to add into it so that it will work fine from setup
also?
Thanks.

No comments:

Post a Comment