本文整理汇总了C#中System.AppDomain.DoCallBack方法的典型用法代码示例。如果您正苦于以下问题:C# AppDomain.DoCallBack方法的具体用法?C# AppDomain.DoCallBack怎么用?C# AppDomain.DoCallBack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.AppDomain
的用法示例。
在下文中一共展示了AppDomain.DoCallBack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateRemoteHost
protected override HostedService CreateRemoteHost(AppDomain appDomain)
{
appDomain.SetData("ConnectionString",_connectionString);
appDomain.DoCallBack(SetConnectionStringInAppDomain);
var service = base.CreateRemoteHost(appDomain);
return service;
}
示例2: ConfigureNewDomain
public void ConfigureNewDomain(AppDomain domain)
{
if (!string.IsNullOrWhiteSpace(AssemblyFolder))
domain.SetData("Folder", AssemblyFolder);
if (domain == AppDomain.CurrentDomain)
ResolveCustomAssemblies();
else
domain.DoCallBack(new CrossAppDomainDelegate(ResolveCustomAssemblies));
}
示例3: Load
public static void Load(AppDomain domain, string file, Action<Assembly> callback)
{
Asm asm = new Asm() { asmfile = file, handler = callback };
try
{
domain.DoCallBack(new CrossAppDomainDelegate(asm.loadAsmFile));
}
catch (Exception ex)
{
Console.WriteLine($"Failed to load one of the assembly into domain {domain.FriendlyName}: {ex.Message}");
}
}
示例4: ClassInitialize
//[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
_serverDomain = AppDomain.CreateDomain("ServerDomain #2", AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation);
_serverDomain.DoCallBack(() =>
{
var serverChannel = new IpcServerChannel("ipc server #2", "localhost:9091", new ProtobufServerFormatterSinkProvider { FallbackToBinaryFormatter = true });
ChannelServices.RegisterChannel(serverChannel, false);
RemotingServices.Marshal(new TestServer(), "TestServer", typeof(ITestServer));
});
_clientChannel = new IpcClientChannel("ipc client #2", new BinaryClientFormatterSinkProvider());
ChannelServices.RegisterChannel(_clientChannel, false);
_testServer = (ITestServer)Activator.GetObject(typeof(TestServer), "ipc://localhost:9091/TestServer");
}
示例5: Reload
/// <summary>
/// The loaded Assembly will be unloaded together with the AppDomain, when a new Assembly is loaded.
/// Requires all used types to be Serializable.
/// </summary>
public void Reload()
{
// Requires all types to be Serializable, System.Net.Sockets.Socket is not!
if (_appDomain != null)
{
AppDomain.Unload(_appDomain);
}
byte[] bytes = File.ReadAllBytes(_dllPath);
_appDomain = AppDomain.CreateDomain(ASSEMBLY_NAME);
AsmLoader asm = new AsmLoader()
{
Data = bytes
};
_appDomain.DoCallBack(asm.LoadAsm);
AsyncSocketFactory = (IAsyncSocketFactory)asm.Assembly.CreateInstance(FULLY_QUALIFIED_TYPE_NAME);
}
示例6: MethodToBeRun
private static void MethodToBeRun(AppDomain appDomain)
{
appDomain.DoCallBack(() =>
{
AppDomain myDomain = AppDomain.CurrentDomain;
Console.WriteLine("Im in '{0}' domain", myDomain.FriendlyName);
for (int i = 0; i < 10000000; i++)
{
Console.WriteLine("Im in domain in {0}", myDomain.GetHashCode());
}
//Accessing outerscope varible, not possible in AppDomain, will generate error.
// Console.WriteLine(abc);
//For simple hang up.
Console.ReadLine();
}
);
}
示例7: FlowEnvironment
public FlowEnvironment(string path)
{
File = new FileInfo(path);
if (!File.Exists)
throw new FileNotFoundException("Unable to find the specified file path");
// Create a new domain
string domainName = string.Format("FlowEnvironment.0x{0:X8}", GetHashCode());
domain = AppDomain.CreateDomain(domainName);
// Preload common assemblies
domain.DoCallBack(PreloadAssemblies);
// Load the specified flow
Reload();
// Watch the specified path
watcher = new FileSystemWatcher();
watcher.Path = File.DirectoryName;
watcher.Filter = File.Name;
watcher.Changed += Watcher_Changed;
watcher.EnableRaisingEvents = true;
}
示例8: LoadSiloInNewAppDomain
private Silo LoadSiloInNewAppDomain(string siloName, Silo.SiloType type, ClusterConfiguration config, out AppDomain appDomain)
{
AppDomainSetup setup = GetAppDomainSetupInfo();
appDomain = AppDomain.CreateDomain(siloName, null, setup);
// Load each of the additional assemblies.
Silo.TestHooks.CodeGeneratorOptimizer optimizer = null;
foreach (var assembly in this.additionalAssemblies.Where(asm => asm.Value != null))
{
if (optimizer == null)
{
optimizer =
(Silo.TestHooks.CodeGeneratorOptimizer)
appDomain.CreateInstanceFromAndUnwrap(
"OrleansRuntime.dll",
typeof(Silo.TestHooks.CodeGeneratorOptimizer).FullName,
false,
BindingFlags.Default,
null,
null,
CultureInfo.CurrentCulture,
new object[] { });
}
optimizer.AddCachedAssembly(assembly.Key, assembly.Value);
}
var args = new object[] { siloName, type, config };
var silo = (Silo)appDomain.CreateInstanceFromAndUnwrap(
"OrleansRuntime.dll", typeof(Silo).FullName, false,
BindingFlags.Default, null, args, CultureInfo.CurrentCulture,
new object[] { });
appDomain.UnhandledException += ReportUnobservedException;
appDomain.DoCallBack(RegisterPerfCountersTelemetryConsumer);
return silo;
}
示例9: StartServers
public static void StartServers(TestContext ctx)
{
#region TCP Duplex
// Setup TCP Duplex Server AppDomain
AppDomainSetup tcpDuplexAppDomainSetup = new AppDomainSetup() { ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) };
_tcpDuplexServerAppDomain = AppDomain.CreateDomain("RecreateClientConnectionTests_Server", null, tcpDuplexAppDomainSetup);
_tcpDuplexServerAppDomain.Load(typeof(ZyanConnection).Assembly.GetName());
// Start Zyan host inside the TCP Duplex Server AppDomain
var tcpDuplexServerWork = new CrossAppDomainDelegate(() =>
{
var server = TcpDuplexServerHostEnvironment.Instance;
if (server != null)
{
Console.WriteLine("TCP Duplex Server running.");
}
});
_tcpDuplexServerAppDomain.DoCallBack(tcpDuplexServerWork);
#endregion
#region TCP Simplex
// Setup TCP Simplex Server AppDomain
AppDomainSetup tcpSimplexAppDomainSetup = new AppDomainSetup() { ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) };
_tcpSimplexServerAppDomain = AppDomain.CreateDomain("RecreateClientConnectionTests_Server", null, tcpSimplexAppDomainSetup);
_tcpSimplexServerAppDomain.Load(typeof(ZyanConnection).Assembly.GetName());
// Start Zyan host inside the TCP Simplex Server AppDomain
var tcpSimplexServerWork = new CrossAppDomainDelegate(() =>
{
var server = TcpSimplexServerHostEnvironment.Instance;
if (server != null)
{
Console.WriteLine("TCP Simplex Server running.");
}
});
_tcpSimplexServerAppDomain.DoCallBack(tcpSimplexServerWork);
#endregion
}
示例10: CreateAppDomain
private void CreateAppDomain()
{
var appDomainSetup = new AppDomainSetup
{
ApplicationBase = applicationPath,
};
if (shadowCache)
{
appDomainSetup.ShadowCopyFiles = "true";
appDomainSetup.CachePath = Path.Combine(applicationPath, CacheFolder);
}
// Create AppDomain
appDomain = AppDomain.CreateDomain(appDomainName, AppDomain.CurrentDomain.Evidence, appDomainSetup);
// Create appDomain Callback
appDomainCallback = new AssemblyLoaderCallback(AssemblyLoaded, mainAssemblyPath);
// Install the appDomainCallback to prepare the new app domain
appDomain.DoCallBack(appDomainCallback.RegisterAssemblyLoad);
}
示例11: Main
public static int Main(string[] args)
{
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
_serverAppDomain = AppDomain.CreateDomain("Server", null, setup);
_serverAppDomain.Load(typeof(ZyanConnection).Assembly.GetName());
CrossAppDomainDelegate serverWork = new CrossAppDomainDelegate(() =>
{
var server = EventServer.Instance;
if (server != null)
{
Console.WriteLine("Event server started.");
}
});
_serverAppDomain.DoCallBack(serverWork);
// Test IPC Binary
int ipcBinaryTestResult = IpcBinaryTest.RunTest();
Console.WriteLine("Passed: {0}", ipcBinaryTestResult == 0);
// Test TCP Binary
int tcpBinaryTestResult = TcpBinaryTest.RunTest();
Console.WriteLine("Passed: {0}", tcpBinaryTestResult == 0);
// Test TCP Custom
int tcpCustomTestResult = TcpCustomTest.RunTest();
Console.WriteLine("Passed: {0}", tcpCustomTestResult == 0);
// Test TCP Duplex
int tcpDuplexTestResult = TcpDuplexTest.RunTest();
Console.WriteLine("Passed: {0}", tcpDuplexTestResult == 0);
// Test HTTP Custom
int httpCustomTestResult = HttpCustomTest.RunTest();
Console.WriteLine("Passed: {0}", httpCustomTestResult == 0);
// Test NULL Channel
const string nullChannelResultSlot = "NullChannelResult";
_serverAppDomain.DoCallBack(new CrossAppDomainDelegate(() =>
{
int result = NullChannelTest.RunTest();
AppDomain.CurrentDomain.SetData(nullChannelResultSlot, result);
}));
var nullChannelTestResult = Convert.ToInt32(_serverAppDomain.GetData(nullChannelResultSlot));
Console.WriteLine("Passed: {0}", nullChannelTestResult == 0);
// Stop the event server
EventServerLocator locator = _serverAppDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, "IntegrationTest_DistributedEvents.EventServerLocator") as EventServerLocator;
locator.GetEventServer().Dispose();
Console.WriteLine("Event server stopped.");
if (!MonoCheck.IsRunningOnMono || MonoCheck.IsUnixOS)
{
// Mono/Windows bug:
// AppDomain.Unload freezes in Mono under Windows if tests for
// System.Runtime.Remoting.Channels.Tcp.TcpChannel were executed.
AppDomain.Unload(_serverAppDomain);
Console.WriteLine("Server AppDomain unloaded.");
}
if (ipcBinaryTestResult + tcpBinaryTestResult + tcpCustomTestResult + tcpDuplexTestResult + httpCustomTestResult + nullChannelTestResult == 0)
{
Console.WriteLine("All tests passed.");
return 0;
}
return 1;
}
示例12: GetCreator
internal static IPluginCreator GetCreator(AppDomain domain, ILoggerFactory logfactory)
{
if (domain == null)
throw new ArgumentNullException("domain");
if (logfactory == null)
throw new ArgumentNullException("logfactory");
IPluginCreator creator = domain.GetData(PLUGINCREATORKEY) as IPluginCreator;
if (creator == null)
{
domain.SetData(LOGGERFACTORYKEY, new ProxyLoggerFactory(logfactory));
domain.DoCallBack(() =>
{
Logger.Singleton.LoggerFactory = AppDomain.CurrentDomain.GetData(LOGGERFACTORYKEY) as ILoggerFactory;
AppDomain.CurrentDomain.SetData(PLUGINCREATORKEY, new PluginCreator());
});
domain.SetData(LOGGERFACTORYKEY, null);
creator = domain.GetData(PLUGINCREATORKEY) as IPluginCreator;
}
return creator;
}
示例13: LoadPluginsIntoAppDomain
private static void LoadPluginsIntoAppDomain()
{
lock (SyncLock)
{
pluginDomain = AppDomain.CreateDomain("PluginDomain");
pluginDomain.UnhandledException += (sender, e) => Logger.Error("Plugin app-domain crashed.", (Exception)e.ExceptionObject);
pluginDomain.DoCallBack(() => log4net.Config.XmlConfigurator.Configure(new FileInfo(Path.Combine(InstallationDirectory, "NpsPlugin.config"))));
pluginDomain.DoCallBack(LoadPlugins);
}
}
示例14: LoadFrom
public static void LoadFrom(AppDomain appDomain,string file)
{
appDomain.SetData(Thread.CurrentThread.ManagedThreadId + "LoadFile", file);
appDomain.DoCallBack(() =>
{
Assembly ass2 = Assembly.LoadFrom((string)AppDomain.CurrentDomain.GetData(Thread.CurrentThread.ManagedThreadId + "LoadFile"));
});
}
示例15: RunInAppDomain
public static object RunInAppDomain(Delegate delg, AppDomain targetDomain, params object[] args) {
var runner = new domainDomainRunner(delg, args, delg.GetHashCode());
targetDomain.DoCallBack(runner.Invoke);
return targetDomain.GetData("appDomainResult" + delg.GetHashCode());
}