Form Freezing

Ask general questions here.
User avatar
Gunner1980
Posts: 89
Joined: Mon Apr 05, 2010 8:44 pm
Location: Austin, Texas

Form Freezing

Post by Gunner1980 » Thu Aug 04, 2011 4:58 pm

I am trying to launch a simple form with a few buttons on it which I made using designer. I am trying to show the form in a recordings user code using the following code and am having issues.

Code: Select all

             

public void AwaitingDataForm()
{   
CommonUtilLib.Forms.AwaitingDataForm ADform = new CommonUtilLib.Forms.AwaitingDataForm();
ADform.Show();
}

When I launch the form in this manner it shows up however only half of the data is present in the form and when I click on the form it says it is not responding and crashes. I have read around and thought that there may be a threading issue so I tried the following code but it gave me the same issue.

Code: Select all

        
public void NewThread()
        {
            Thread thread = new Thread(new ThreadStart(WorkThreadFunction));
            thread.Start();
        }
        
        public void WorkThreadFunction()
        {
            try
            {
                CommonUtilLib.Forms.AwaitingDataForm ADform = new CommonUtilLib.Forms.AwaitingDataForm();
                ADform.Show();
            }
            catch (Exception ex)
            {
                
            }   

Has anyone else launched a custom form from within user code? If so how do you do it?

Thanks in advance

User avatar
sdaly
Posts: 238
Joined: Mon May 10, 2010 11:04 am
Location: Dundee, Scotland

Re: Form Freezing

Post by sdaly » Thu Aug 04, 2011 6:12 pm

Have you tried .ShowDialog instead of .Show?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Form Freezing

Post by Support Team » Thu Aug 04, 2011 6:17 pm

Windows Forms controls need threads with an STA model, so make sure you set the apartment state of the thread:
thread.SetApartmentState(ApartmentState.STA);
Then you can try to use Application.Run to show the form:
System.Windows.Forms.Application.Run(ADform);
Regards,
Alex
Ranorex Team
.
Image