I found that MC.NET can have one static class which have two different values.
I wonder how it is possible and how to prevent this situation.
Reproduce scenario is very simple.
1. create function
namespace PowerLanguage
{
namespace Function
{
public static class MyGlobal
{
public static int global_int = 10;
}
}
}
2. create indicator
public _i_write_100(object _ctx):base(_ctx){}
protected override void Create() {
}
protected override void StartCalc() {
MyGlobal.global_int = 100;
Output.WriteLine("_i_write_100: MyGlobal.global_int = {0}", MyGlobal.global_int);
}
protected override void CalcBar(){
}
}
3. create indicator
public class _i_write_200 : IndicatorObject {
public _i_write_200(object _ctx):base(_ctx){}
protected override void Create() {
}
protected override void StartCalc() {
MyGlobal.global_int = 200;
Output.WriteLine("_i_write_200: MyGlobal.global_int = {0}", MyGlobal.global_int);
}
protected override void CalcBar(){
}
}
4. create indicator
public class _i_read : IndicatorObject {
public _i_read(object _ctx):base(_ctx){}
protected override void Create() {
}
protected override void StartCalc() {
Output.WriteLine("_i_read: MyGlobal.global_int = {0}", MyGlobal.global_int);
}
protected override void CalcBar(){
}
}
5. In a chart, apply _i_write_100
6. apply _i_read, the variable has value 100
7. In PLEditor, edit function and change to public static int global_int = -10; and recompile
8. apply _i_write_200
9. apply _i_read, the variable has value 200
10. "Format Objects" windows, change the first _i_read status to off and then on.
the variable has value 100.
11. "Format Objects" windows, change the second _i_read status to off and then on.
the variable has value 200.
Two indicators have two different value 100, and 200 for static class's static member.
As I know, static class is one and no need to instantiate.
If step 7 is omitted, then both step 10 and 11 will show value 200.
I wonder how it is possible in MC.NET ?
To prevent,
Is it necessary to recreate all indicators and signals after edit and recompile code file holding global variable ?
Is it necessary to recreate all indicators and signals after edit and recompile of any of indicators, signals, functions which results in new PLStudies2010.dll which holds the global variable?
For reproduction, I attached test_static_clss.pln which create function _f_lifetime_global, and 3 indicators.
one static class which have two different values [SOLVED]
-
- Posts: 39
- Joined: 29 Nov 2007
- Has thanked: 8 times
- Been thanked: 2 times
one static class which have two different values
- Attachments
-
- test_static_class.pln
- (1.42 KiB) Downloaded 301 times
-
- Posts: 39
- Joined: 29 Nov 2007
- Has thanked: 8 times
- Been thanked: 2 times
Re: one static class which have two different values
I found that any of indicator, signal, function recompilation create new assembly for all of indicators, signals and functions.
After it is created, applying indicators and signals use this new assembly.
Applying a study, recompiling any of the study, applying a study, recompiling any of the study, .... 4 times resulted in loading of 4 assemblies in Multicharts64.exe process.
C:\ProgramData\TS Support\MultiCharts .NET64\StudyServer\Techniques\CompAssms\0a42d1i2\0a42d1i2.dll
C:\ProgramData\TS Support\MultiCharts .NET64\StudyServer\Techniques\CompAssms\0a42d1i2\0a42d1i2.dll.CS.netmodule
C:\ProgramData\TS Support\MultiCharts .NET64\StudyServer\Techniques\CompAssms\mdryhaai\mdryhaai.dll
C:\ProgramData\TS Support\MultiCharts .NET64\StudyServer\Techniques\CompAssms\mdryhaai\mdryhaai.dll.CS.netmodule
C:\ProgramData\TS Support\MultiCharts .NET64\StudyServer\Techniques\CompAssms\ug4sm0ce\ug4sm0ce.dll
C:\ProgramData\TS Support\MultiCharts .NET64\StudyServer\Techniques\CompAssms\ug4sm0ce\ug4sm0ce.dll.CS.netmodule
C:\ProgramData\TS Support\MultiCharts .NET64\StudyServer\Techniques\CompAssms\yaxcu3wx\yaxcu3wx.dll
C:\ProgramData\TS Support\MultiCharts .NET64\StudyServer\Techniques\CompAssms\yaxcu3wx\yaxcu3wx.dll.CS.netmodule
Considering this, Global Variable across these 4 assembly is not possible, I think. or Is there any way to make it?
The requirement for correct working of Global Variable is that only one assembly should be maintained in Multicharts64.exe process.
That is, any one of study is recompiled and a study is applied, then a new assembly will load into memory and studies applied after new assembly is created, can not share information with studies applied with previous assembly.
yaxcu3wx.dll is the primary module of assembly which has assembly manifest metadata, yaxcu3wx.dll.CS.netmodule is a module of the assembly which has all indicators, signals, functions.
Combining these two is equivalent to C:\ProgramData\TS Support\MultiCharts .NET64\StudyServer\Techniques\CS\bin\Debug\PLStudies2010.dll.
Is my understanding correct? or am I misunderstanding on the limitation in implementing Global Variable?
After it is created, applying indicators and signals use this new assembly.
Applying a study, recompiling any of the study, applying a study, recompiling any of the study, .... 4 times resulted in loading of 4 assemblies in Multicharts64.exe process.
C:\ProgramData\TS Support\MultiCharts .NET64\StudyServer\Techniques\CompAssms\0a42d1i2\0a42d1i2.dll
C:\ProgramData\TS Support\MultiCharts .NET64\StudyServer\Techniques\CompAssms\0a42d1i2\0a42d1i2.dll.CS.netmodule
C:\ProgramData\TS Support\MultiCharts .NET64\StudyServer\Techniques\CompAssms\mdryhaai\mdryhaai.dll
C:\ProgramData\TS Support\MultiCharts .NET64\StudyServer\Techniques\CompAssms\mdryhaai\mdryhaai.dll.CS.netmodule
C:\ProgramData\TS Support\MultiCharts .NET64\StudyServer\Techniques\CompAssms\ug4sm0ce\ug4sm0ce.dll
C:\ProgramData\TS Support\MultiCharts .NET64\StudyServer\Techniques\CompAssms\ug4sm0ce\ug4sm0ce.dll.CS.netmodule
C:\ProgramData\TS Support\MultiCharts .NET64\StudyServer\Techniques\CompAssms\yaxcu3wx\yaxcu3wx.dll
C:\ProgramData\TS Support\MultiCharts .NET64\StudyServer\Techniques\CompAssms\yaxcu3wx\yaxcu3wx.dll.CS.netmodule
Considering this, Global Variable across these 4 assembly is not possible, I think. or Is there any way to make it?
The requirement for correct working of Global Variable is that only one assembly should be maintained in Multicharts64.exe process.
That is, any one of study is recompiled and a study is applied, then a new assembly will load into memory and studies applied after new assembly is created, can not share information with studies applied with previous assembly.
yaxcu3wx.dll is the primary module of assembly which has assembly manifest metadata, yaxcu3wx.dll.CS.netmodule is a module of the assembly which has all indicators, signals, functions.
Combining these two is equivalent to C:\ProgramData\TS Support\MultiCharts .NET64\StudyServer\Techniques\CS\bin\Debug\PLStudies2010.dll.
Is my understanding correct? or am I misunderstanding on the limitation in implementing Global Variable?
-
- Posts: 39
- Joined: 29 Nov 2007
- Has thanked: 8 times
- Been thanked: 2 times
Re: one static class which have two different values
Now, I understood why MC.NET runs simultaneously several dll for indicatiors, signals and functions.
If only one is used, then we have to exit MC.NET every time we recompile, since currently used dll can not be overwritten.
But the side effect is that indictors, signals and functions can be running on different dlls.
I thought there is only one dll running for all indicators, signals and functions, thus variables defined on this one dll can be used as global variable without problem.
But it was not the case, according to my observation up to now.
If only one is used, then we have to exit MC.NET every time we recompile, since currently used dll can not be overwritten.
But the side effect is that indictors, signals and functions can be running on different dlls.
I thought there is only one dll running for all indicators, signals and functions, thus variables defined on this one dll can be used as global variable without problem.
But it was not the case, according to my observation up to now.
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: one static class which have two different values [SOLVED]
Hello chi jeongki,
When one changes the code of the function (class), which is used in several indicators or signals, that is required to use the “Recompile all” option. In this case the references to this function will be renewed in all studies. Otherwise the new reference will only be applied to the studies that are not added to charts.
The “Compile” option only recompiles those studies that were changed. The first indicator’s code wasn’t changed and therefore it wasn’t recompiled, so it continued working from the previous assembly (there is no way the application can check if the linked/related objects were changed). The second indicator was not applied to a chart at the moment of compilation, so it was recompiled and the new assembly will be used for it, should the user apply it to the chart. That is why it is important to use the “Recompile all” option.
When one changes the code of the function (class), which is used in several indicators or signals, that is required to use the “Recompile all” option. In this case the references to this function will be renewed in all studies. Otherwise the new reference will only be applied to the studies that are not added to charts.
The “Compile” option only recompiles those studies that were changed. The first indicator’s code wasn’t changed and therefore it wasn’t recompiled, so it continued working from the previous assembly (there is no way the application can check if the linked/related objects were changed). The second indicator was not applied to a chart at the moment of compilation, so it was recompiled and the new assembly will be used for it, should the user apply it to the chart. That is why it is important to use the “Recompile all” option.
-
- Posts: 39
- Joined: 29 Nov 2007
- Has thanked: 8 times
- Been thanked: 2 times
Re: one static class which have two different values
Thank you for clear explanation.
Now, I got more understanding how to use MC.NET properly.
Now, I got more understanding how to use MC.NET properly.