问题
Can't figure why cross-domain calls is so slow for FrameworkElementAdapters
class. Here is a simple code:
class Program
{
[STAThread]
static void Main()
{
AppDomain domain = AppDomain.CreateDomain("AnotherDomain");
var instance = (AnotherDomainClass) domain.CreateInstanceAndUnwrap(
typeof (AnotherDomainClass).Assembly.FullName,
typeof (AnotherDomainClass).FullName);
var contract = instance.CreateContract();
}
}
class AnotherDomainClass : MarshalByRefObject
{
public INativeHandleContract CreateContract()
{
return FrameworkElementAdapters.ViewToContractAdapter(
new TextBlock());
}
}
The execution time of the last line instance.CreateContract
is near 1.7 sec! Where is a problem?
回答1:
Have you tried decorating your Main method with the LoaderOptimizationAttribute set to LoaderOptimization.MultiDomainHost
?
The FrameworkElementAdapters
class is part of System.AddIn. Have a look at Add-In Performance: What can you expect as you cross an isolation boundary and how to make it better form the blog of the System.AddIn team. Also have a look at the "Perfomance Optimization" section of the WPF Add-Ins Overview MSDN article.
来源:https://stackoverflow.com/questions/16155189/performance-of-the-frameworkelementadapters-class