471,350 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Dynamically loading Assemblies within a Windows Service

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
--

Jul 16 '08 #1
3 1943
This article describes a whole infrastructure for doing more or less what
you describe:
http://www.eggheadcafe.com/articles/20041204.asp
Peter
"Matthias S." <ma**********************@googlemail.comwrote in message
news:xn***************@news.microsoft.com...
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
--
Jul 16 '08 #2
On Jul 16, 9:17*am, "Matthias S."
<matthias.st_SP_AM_TR_...@googlemail.comwrote:
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.
Jul 16 '08 #3
The assemblies CANNOT be unload.

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

Jul 17 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Doug | last post: by
4 posts views Thread by Yoni Gibbs | last post: by
1 post views Thread by BillyMac | last post: by
reply views Thread by Verane | last post: by
8 posts views Thread by =?Utf-8?B?TWFyaw==?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.