Form Freezing : General Questions

Form Freezing

Ask general questions here.

Form Freezing

Postby Gunner1980 » Thu Aug 04, 2011 5: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
Gunner1980
 
Posts: 89
Joined: Mon Apr 05, 2010 9:44 pm
Location: Austin, Texas

Re: Form Freezing

Postby sdaly » Thu Aug 04, 2011 7:12 pm

Have you tried .ShowDialog instead of .Show?
User avatar
sdaly
 
Posts: 213
Joined: Mon May 10, 2010 12:04 pm
Location: Dundee, Scotland

Re: Form Freezing

Postby Support Team » Thu Aug 04, 2011 7: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
User avatar
Support Team
Site Admin
 
Posts: 4843
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria


Return to General Questions

Who is online

Users browsing this forum: No registered users and 0 guests