473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Help regarding assemblies

Max
Hi,

I would like to be able to load an assembly file at runtime which will do some work. When the work is done
I would like the main application to be informed so that the assembly can be unloaded. How can I do this using
delegates and events?

Nov 17 '05 #1
4 1224
Hi,
You load the assembly using Assembly.Load*

AFAIK there is no method to unload an assembly. Why you want to do this?

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Max" <ma******@yahoo.com> wrote in message
news:et**************@TK2MSFTNGP12.phx.gbl...
Hi,

I would like to be able to load an assembly file at runtime which will
do some work. When the work is done
I would like the main application to be informed so that the assembly can
be unloaded. How can I do this using
delegates and events?

Nov 17 '05 #2
Max
I didn't really mean to say unload assembly but rather just unload the whole application domain. You see I got this library that
opens Outlook.exe and does some work, and when the user closes Outlook, the library marshals all the objects and shutsdown the
server (outlook.exe). I would also like to unload the whole application domain as well just to make sure everything is killed, so I
would have something like this:

System.AppDomain newDomain = System.AppDomain.CreateDomain("OutlookApplicationD omain");
newDomain.ExecuteAssembly(@"c:\OpenOutlook.exe");

But since outlook is controlled by the user I need some event to get back to the main application before I unload the domain:

System.AppDomain.Unload(newDomain);

Any idea how to do this?

Cheers,
Max

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,
You load the assembly using Assembly.Load*

AFAIK there is no method to unload an assembly. Why you want to do this?

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Max" <ma******@yahoo.com> wrote in message news:et**************@TK2MSFTNGP12.phx.gbl...
Hi,

I would like to be able to load an assembly file at runtime which will do some work. When the work is done
I would like the main application to be informed so that the assembly can be unloaded. How can I do this using
delegates and events?



Nov 17 '05 #3

"Max" <ma******@yahoo.com> wrote in message
news:et**************@TK2MSFTNGP12.phx.gbl...
Hi,

I would like to be able to load an assembly file at runtime which will
do some work. When the work is done
I would like the main application to be informed so that the assembly can
be unloaded. How can I do this using
delegates and events?


You can't unload assemblies, you can only unload application domains (AD),
however, you can't unload the default AD, so you'll need to create an extra
AD, load your assembly into that domain, create an instance of a type and
call a method on that type. When the method returns you can unload the AD to
get rid of the AD and the assemblies loaded into that AD.
Check MSDN for info and samples, keywords are CreateDomain,
CreateInstanceFromAndUnwrap, Unload....

Willy.


Nov 17 '05 #4
When you call ExecuteAssembly, the call returns when your OpenOutlook.exe
Main function returns, that is when you have done in your Main function, so
there is no need for an event, just unload the AD when the call returns.
Don't forget that your OpenOutlook.exe Main function runs on the callers
thread, so you probably want to create an auxiliary thread to run this code,
and because you are using COM interop in that assembly you'll have to
initialize the thread to enter a STA before starting.

Thread t = new...
t.ApartmentState= ApartmentState.STA;
t.Start();

Note also that you might want to change the assembly type from an exe into a
DLL and use CreateInstanceAndUnwrap to load a type in an auxiliary AD.

Willy.

"Max" <ma******@yahoo.com> wrote in message
news:O6*************@TK2MSFTNGP09.phx.gbl...
I didn't really mean to say unload assembly but rather just unload the
whole application domain. You see I got this library that opens
Outlook.exe and does some work, and when the user closes Outlook, the
library marshals all the objects and shutsdown the server (outlook.exe). I
would also like to unload the whole application domain as well just to
make sure everything is killed, so I would have something like this:

System.AppDomain newDomain =
System.AppDomain.CreateDomain("OutlookApplicationD omain");
newDomain.ExecuteAssembly(@"c:\OpenOutlook.exe");

But since outlook is controlled by the user I need some event to get back
to the main application before I unload the domain:

System.AppDomain.Unload(newDomain);

Any idea how to do this?

Cheers,
Max

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote in message news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,
You load the assembly using Assembly.Load*

AFAIK there is no method to unload an assembly. Why you want to do this?

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Max" <ma******@yahoo.com> wrote in message
news:et**************@TK2MSFTNGP12.phx.gbl...
Hi,

I would like to be able to load an assembly file at runtime which will
do some work. When the work is done
I would like the main application to be informed so that the assembly
can be unloaded. How can I do this using
delegates and events?


Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ratnakar Pedagani | last post by:
Hi, I'm new to c# programming. I need help regarding a form which contains a help in the main menu. upon clicking the sub items of help menu, i should be able to display a pop up displaying the...
2
by: sachin | last post by:
Hello Everybody I need some help regarding Natural Language Processing. I am designing a MT system from a SOV language to a SOV language. I need a parser which can find the root word...
1
by: Atul Sharma | last post by:
hi friends i m getting problem regarding wht assemblies are? why they r used? & how they r created?
5
by: archana | last post by:
Hi all, I am having confusion regarding localization in .net. I have one form on which i have some labels and button. After designing that form what i did is set localization property of form...
2
by: xyzbindu | last post by:
hello, iam a student & need help regarding UPDATE method of dataadapter when i update the database using dataadpter.update(dataset,tablename) i get the following error an unhandled exception of...
1
by: chandrapsg | last post by:
Hi, i am working with jsp .. i wanna help regarding how to import or how to call python modules to jsp if a piece of code is availabe will be very helpful for me chandra
2
by: sindhu sweet | last post by:
Hi friends, I am developing an IDE using java...as part of my project...i am half the way(hav created menus FILE, FONT,TEXTAREA,SCROLLBARS on both sides...) i need some help....can anyone refer...
5
by: dannynnad | last post by:
Hi, SuperAdministrator when trying to edit the frontend content the following error is comingup: "You are not authorized to view this resource." I checked from the backend whether the...
4
by: bsonline | last post by:
I hv a datetime format like '24/01/2008 15:56:01' . Now I have to select dates from a date range, but input datetime format like 24/1/2008 15:56:01'. I hv written the query like : "select...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.