Hi,
I'm currently writing a scheduling service which starts a number DotNet
executables, each within a new AppDomain, every ten seconds.
The guts of the code is as follows:
// For each executable in the list of tasks
for (int i = 0; i < this.processTasks.Length; i++)
{
try
{
// Create a suitable name for the AppDomain
string[] taskArgs = this.processTasks[i].Trim().Split(' ');
string appDomainName = String.Format("Task {0}", i);
// Create a new AppDomain for the task
Trace.WriteLine(String.Format("Creating AppDomain '{0}'",
appDomainName));
AppDomain appDomain = AppDomain.CreateDomain(appDomainName);
try
{
// Execute the assembly in the AppDomain
Trace.WriteLine(String.Format("Executing assembly '{0}' on AppDomain
'{1}'", taskArgs[0], appDomain.FriendlyName));
appDomain.ExecuteAssembly(taskArgs[0],
AppDomain.CurrentDomain.Evidence, taskArgs);
}
catch (Exception e)
{
// Log any errors
Trace.WriteLine(e.ToString(), EVENT_SOURCE);
EventLog.WriteEntry(EVENT_SOURCE, e.ToString(),
EventLogEntryType.Error);
}
finally
{
// Unload the AppDomain
Trace.WriteLine(String.Format("Unloading AppDomain '{0}'",
appDomain.FriendlyName));
AppDomain.Unload(appDomain);
}
}
catch (Exception e)
{
// Log any errors that may be thrown in the finally block above
At the moment, because I have six executables in the processTasks array, 6
new AppDomains are created and destroyed on every pass.
As time has gone on (the schedule process has been running for several
days), the time taken to create/destroy an AppDomain has gone from 1s to
about 12s, and the memory usage of the process has crept steadily upwards.
Should I be creating and destroying AppDomains with this rapidity, or are
they simply not designed for this use? Or am I not getting rid of them
properly with the simple AppDomain.Unload().
Any info very greatefully received!!
Many thanks,
Chris. 4 2249
If you are starting the same apps every 10 seconds, consider making them
services that run their business every 10 seconds instead. This will be much
less overhead on the system.
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"Chris Lacey" wrote: Hi,
I'm currently writing a scheduling service which starts a number DotNet executables, each within a new AppDomain, every ten seconds.
The guts of the code is as follows:
// For each executable in the list of tasks for (int i = 0; i < this.processTasks.Length; i++) { try { // Create a suitable name for the AppDomain string[] taskArgs = this.processTasks[i].Trim().Split(' '); string appDomainName = String.Format("Task {0}", i);
// Create a new AppDomain for the task Trace.WriteLine(String.Format("Creating AppDomain '{0}'", appDomainName)); AppDomain appDomain = AppDomain.CreateDomain(appDomainName);
try { // Execute the assembly in the AppDomain Trace.WriteLine(String.Format("Executing assembly '{0}' on AppDomain '{1}'", taskArgs[0], appDomain.FriendlyName)); appDomain.ExecuteAssembly(taskArgs[0], AppDomain.CurrentDomain.Evidence, taskArgs); } catch (Exception e) { // Log any errors Trace.WriteLine(e.ToString(), EVENT_SOURCE); EventLog.WriteEntry(EVENT_SOURCE, e.ToString(), EventLogEntryType.Error); } finally { // Unload the AppDomain Trace.WriteLine(String.Format("Unloading AppDomain '{0}'", appDomain.FriendlyName)); AppDomain.Unload(appDomain); } } catch (Exception e) { // Log any errors that may be thrown in the finally block above
At the moment, because I have six executables in the processTasks array, 6 new AppDomains are created and destroyed on every pass.
As time has gone on (the schedule process has been running for several days), the time taken to create/destroy an AppDomain has gone from 1s to about 12s, and the memory usage of the process has crept steadily upwards.
Should I be creating and destroying AppDomains with this rapidity, or are they simply not designed for this use? Or am I not getting rid of them properly with the simple AppDomain.Unload().
Any info very greatefully received!!
Many thanks,
Chris.
Thanks, Gregory.
The single service that schedules all of the other applications is required
because the list of executables is determined by the end user (in a
configuration file). We also need to be sure that these run sequentially,
and not in parallel.
AppDomains seem like the right thing to use here - and I can cope with a
small (consistent!) delay in creating and destroying them - but the
increasing memory usage and creation time seems to imply they are not
"fully" destroyed.
Any ideas?
Thanks in advance,
Chris.
"Chris Lacey" <ch*********@bigfoot.com> wrote in message
news:Og**************@TK2MSFTNGP11.phx.gbl... Thanks, Gregory.
The single service that schedules all of the other applications is required because the list of executables is determined by the end user (in a configuration file). We also need to be sure that these run sequentially, and not in parallel.
AppDomains seem like the right thing to use here - and I can cope with a small (consistent!) delay in creating and destroying them - but the increasing memory usage and creation time seems to imply they are not "fully" destroyed.
Any ideas?
Thanks in advance,
Chris.
If I get you right you load six AD, every 10 seconds, that makes 24 * 60 *
36 = 51840 AD/Day, this is quite a lot if you consider the possibility that
some types might leak through the AD boundaries and as such wont be unloaded
when the secondary AD unloads.
I'm also not clear on why you load an .exe assembly in an application
domain, why not simply start the .exe as a separate process? If this is not
possible (which I doubt), I would suggest you to recycle the process every
now and then, say once a day.
Willy.
Chris Lacey wrote: The guts of the code is as follows:
AppDomain appDomain = AppDomain.CreateDomain(appDomainName);
appDomain.ExecuteAssembly(taskArgs[0], AppDomain.CurrentDomain.Evidence, taskArgs);
AppDomain.Unload(appDomain);
As time has gone on (the schedule process has been running for several days), the time taken to create/destroy an AppDomain has gone from 1s to about 12s, and the memory usage of the process has crept steadily upwards.
Should I be creating and destroying AppDomains with this rapidity, or are they simply not designed for this use? Or am I not getting rid of them properly with the simple AppDomain.Unload().
The guts look fine, and Unload IS what you should be doing. My guess
is that you stripped something seemingly innocuous, and that's what's
causing these increasing create/destroy times.
One trick I have found very useful for debugging app domains is to
watch the assemblies loaded into the default appdomain -
AppDomain.CurrentDomain.GetAssemblies(). Buggy app domain code often
'leaks' assemblies into the main domain.
-- www.midnightbeach.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Daylor |
last post by:
in win32 process , when u create new process,u have new main thread.
i know,appDomain r logical procces,that exists in 1 win32 process.
the q:
is there way to create second appDomain (the...
|
by: benben |
last post by:
What is exactly the difference b/w an AppDomain and a Process, they seem to
me very much the same -- boundary for an execution context with protected
resources.
ben
|
by: Chris Lacey |
last post by:
Hi,
I'm currently writing a scheduling service which starts a number DotNet
executables, each within a new AppDomain, every ten seconds.
The guts of the code is as follows:
// For each...
|
by: hB |
last post by:
Hi.
Error = "The configuration system can only be set once. Configuration
system is already set"
Exception Details: System.InvalidOperationException: The
configuration
system can only...
|
by: Chris van de Steeg |
last post by:
In iis6 there is this feature to recycle your appdomain at certain
tresholds, great.
But I recently ran into strange problems when my appdomain was recycled.
When my application starts, it loops...
|
by: José Joye |
last post by:
I'm currently trying to load an instance of a given class within a secondary
appDomain and access it from within my main AppDomain.
Everything is fine and working if the class in the second...
|
by: Bill Woodruff |
last post by:
Visual Studio 2005, .NET FrameWork 2.0, C#, WinForms Application
Hi,
I've read the recent posts by and to 'Thunderbird' (and learned a lot,
thanks, from the usual masters Skeet and Paladino,...
|
by: illegal.prime |
last post by:
Hi all, I'm getting unexpected results when trying to preload
assemblies into an AppDomain I'm creating. Upon creation of the
AppDomain - I attach an AssemblyResolve to both my current AppDomain...
|
by: Tom P. |
last post by:
I am doing quite a bit of custom painting and it means I have to
create a lot of brushes (think one for every file system object in a
directory) per paint. How expensive is this? Should I find a...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
|
by: jack2019x |
last post by:
hello, Is there code or static lib for hook swapchain present?
I wanna hook dxgi swapchain present for dx11 and dx9.
|
by: DizelArs |
last post by:
Hi all)
Faced with a problem, element.click() event doesn't work in Safari browser.
Tried various tricks like emulating touch event through a function:
let clickEvent = new Event('click', {...
| |