Posted 18 years ago by ktaite
Avatar
If I use reflection to call a method which creates a new document window, I don't receive any exceptions but the tabbed document window is not displayed. If call the method directly then the document window is displayed. UIStudio 2.0

See attached code snippet

Sample code

//create a new document
public void CreateTabWindow(string uc, string CaptionName)
{
UserControl uCtrl = null;

try
{
if (uc == "chart") uCtrl = new UnfChart.ctrGigChart();
// Create the document
ActiproSoftware.UIStudio.Dock.DocumentWindow dw = new ActiproSoftware.UIStudio.Dock.DocumentWindow(dockManager1, CaptionName, CaptionName, null, uCtrl);
dw.Activate();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

//if I call this mehtod directly this works
public void OpenNewDocWindow()
{
CreateTabWindow("chart", "trend");
}


//If I call the method the document window does not get displayed
private void UseRef()
{
MethodInfo mi;
object result = null;
try
{
Type otype = this.GetType();
mi = otype.GetMethod("OpenNewDocWindow");
if (mi != null)
{
string typeName = otype.FullName;
object lateBoundObj = Activator.CreateInstance(otype);

result = otype.InvokeMember("OpenNewDocWindow", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, lateBoundObj, null);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

}


Thanks

Comments (2)

Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I think what you're doing here isn't allowed by .NET because the Activator.CreateInstance call is making the controls on a separate thread or something. If you replace Activator.CreateInstance with "this" instead, it works fine.

When I was debugging and still had Activator.CreateInstance in the code, I had run into an exception saying the controls had to be created on the same thread. So somehow, Activator.CreateInstance seems to either be putting them in a different thread or message loop.


Actipro Software Support

Posted 18 years ago by ktaite
Avatar
Thanks

I believe that you are correct that it is a threading issue.
The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.