How to load a class library dll which is never unloaded until MC.NET exits?  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
chi jeongki
Posts: 39
Joined: 29 Nov 2007
Has thanked: 8 times
Been thanked: 2 times

How to load a class library dll which is never unloaded until MC.NET exits?

Postby chi jeongki » 19 Aug 2017

In PLEditor, right button click --> "References..." opens "Assembly References" window.
If a reference is added, and any object in the assembly is referenced from study applied to chart, then the assembly is loaded into memory.

If the study which loaded this assembly is deleted from chart, what happens to this assembly?
If it is not unloaded until MC.NET exits, then this assembly can be a good place to hold Global Variables.

Such dll is irrelevant to the creation of new assembly by compiling studies.
Any object defined in indicator, signal, function (in (PLStudies2010.dll equivalent) can not be a Global Variable across "Compile" (not "Recompile All", "Recompile All" has different problems to consider, migrating connections to outside programs and programming not to depend on the order of study applied to charts)
If all studies are fixed and there is no compile during MC start to exit, then static object defined in this assembly(PLStudies2010.dll equivalent) can work as Global Variable.

Since I am looking for global variable across compile of indicators and signals, dll loaded once during MC start to exit is necessary.
If this dll is unloaded before MC.NET exits, then of course it can not be used as Global Variable storage.

Can MC support team confirm that class library dll which I made, if it is once loaded into memory by any study (I think we have no other way to load dll except study, if there's other way to load dll, please let me know) it will not unloaded until MC exits, regardless of the study which loaded the dll ?

chi jeongki
Posts: 39
Joined: 29 Nov 2007
Has thanked: 8 times
Been thanked: 2 times

Re: How to load a class library dll which is never unloaded until MC.NET exits?

Postby chi jeongki » 19 Aug 2017

One of reason I am looking for this solution is from viewtopic.php?f=19&t=11315#p56843

Caveat: Unless you are supporting legacy code or need interop with an external process (eg. TS) I would NOT recommend going down the path of using GlobalVariable as a crutch. Every variable you put in global variable must be marshalled (copied) from the legacy .dll into/out of mc.net every time you access it. It is fast enough -- unless you are using huge numbers of variables (the values of a time-series). Though it is virtually impossible to debug past the marshalling barrier; so if your app is setting a variable in GV and not returning a valid value later, good luck.

Other reason is it is very simple, no special technique is needed.
No need to call it a Global Variable, it is simply a variable. such as

public static int globalVariable = 3;

which lasts from the first time it is used in a study up to the time MC.NET exits.
The only one check needed is that is it not unloaded until MC.NET exits.

I also found that, in MC.NET, any one of study references the dll, then when MC.NET compiles study, the reference argument is added for the dll.

csc.exe ...... /R:"C:\data\Assembly\GlobalRefDLL\global1\global1\bin\Debug\global1.dll" ......

So, there is no need to add reference to all the studies referencing the variables in global1.dll.

In visual studio, "Add Refercence ..." and select global1.dll is all that is needed.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: How to load a class library dll which is never unloaded until MC.NET exits?  [SOLVED]

Postby Henry MultiСharts » 21 Aug 2017

Hello chi jeongki,

When MultiCharts is closed, everything’s unloaded. Transferring the global variables into another assembly can be a solution in this case, but it is a more complicated solution, compared to recompiling all studies. But if recompilation doesn’t suit you, then this is the only way.

chi jeongki
Posts: 39
Joined: 29 Nov 2007
Has thanked: 8 times
Been thanked: 2 times

Re: How to load a class library dll which is never unloaded until MC.NET exits?

Postby chi jeongki » 21 Aug 2017

OK, then I will move global variables to its own assembly.


Return to “MultiCharts .NET”