Click here to Skip to main content
15,889,691 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
1. I have an application with two dlls (say dll_one,dll_two).
2. dll_One is refered in dll_two
3. The dll_two does some process and a calculated value is made available in a variable say 'Var_Dll_2"
4. When i access dll_one's object from winform , the variable 'Var_Dll_2" should be availabe in dll_one too.

How to achieve this?Please suggest a solution
Posted

1 solution

Don't tray to share variables, share values or objects.
There are several approaches:
1) Any assambly (forget classic dll concept in .net), can define as many classes as you want. So define a static class with a static property and use it to share the value or object. Still, this is not a good approach for many reasons.
2) You can pass parameters to methods by reference (this is default for objects).
3) You can pass parameters by value (scalars) and get results from functions.
Please note, that not the variable itself is interesting, since it is holding only a reference to the value (if it is an object) - but the refernce itself. You can keep as many references to an object as you want. Thus any object can hold a reference to any object, and any method having that reference will be able to change or read that object, indifferent of what the variable is. And does not matter how do you distruburte your classes around assamblies.
 
Share this answer
 
v2
Comments
P.Gnanaraj 5-Feb-15 13:57pm    
Thanks Zoltán Zörgő for the suggestion.I appreciate it and greatful to you.
I have a concern on option 1. During Run time multiple threads will be running and we have multiple 'Var_Dll_2" objects (yes you are rite it is object not variable) . In this case static variable (solution No:1) option will not work ...rite?? Because as per my knowledge "static variables are shared across threads". Please give your suggestion on this
Zoltán Zörgő 5-Feb-15 14:06pm    
This is why it is not so good :) Static properties are by definition not bound to instances but to the class. Thus yes, it will be unique.
You have not told that there will be more than one instances of Var_Dll_2. But you can create a holder static field which can be thread safe. You can use Thread-safe collections for example.

But if you don't need to share instance between the treads, you better not use Option1.
P.Gnanaraj 5-Feb-15 14:12pm    
Thanks Zoltán Zörgő
Zoltán Zörgő 5-Feb-15 14:15pm    
You are welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900