Dynamically loading Assemblies within a Windows Service

  • Thread starter Thread starter Matthias S.
  • Start date Start date
M

Matthias S.

Hi there,

i'm planning on creating a Windows Service, which will have a simple
loop in its OnStart override. In this loop, I dynamically want to load
(job) Assemblies which have a single class implementing a JobInterface
(just an Execute() method). The Service should then execute this method
in a new thread. These Execute() methods won't take more then a couple
of seconds to do what they have to. At the end of the loop in OnStart,
there just will be a Thread.Sleep() causing the Service loop to pause
for some time. After this, the whole loading of assemblies and
executing their Execute() methods will start over again.

Can this be done? i've heard rumors about problems unloading assemblies
again... How do i deal with the service shutdown? Are there any
pitfalls i have to be aware of? I'll be using .net framework 3.0 and c#.

Thanks in advance and greetings from Berlin!

Matthias
--
 
Hi there,

i'm planning on creating a Windows Service, which will have a simple
loop in its OnStart override.

That is a BAD idea, the onStart should be small and fast. Otherwise
you can get a timeout from the system.
Simply create a thread and do the initialization in that thread.
Can this be done? i've heard rumors about problems unloading assemblies
again...

The assemblies CANNOT be unload.
How do i deal with the service shutdown? Are there any
pitfalls i have to be aware of? I'll be using .net framework 3.0 and c#.
You do not need to reload the assemblies though. you do it once (in
the thread spawned in the onStart.
you can create delegates for the methods you need to call and then use
a timer to execute them time and time again.
 
The assemblies CANNOT be unload.

You create a new AppDomain though, load them into that, and then dump the
AppDomain?
 
Back
Top