Method to change default value from c#

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 770
Благодарностей
1 182
Баллы
113
Title says it all...

Just basically a lot of times there is needed to save some value to use for next thread. By now I'm doing that with help of .txt file. Would be good to save some value for future use...

Thanks
 

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 707
Баллы
113
Global variables?)
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 770
Благодарностей
1 182
Баллы
113

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 707
Баллы
113
What exactly do you mean
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 770
Благодарностей
1 182
Баллы
113
As I know to set global variable and then change this variable you need at least two different templates.
Correct ?
 

LexxWork

Client
Регистрация
31.10.2013
Сообщения
1 190
Благодарностей
786
Баллы
113
i don't like use global variables
here is some example how to simulate global vars with linked table
C#:
string prefix = "in_"; //prefix of names for dumpable variables
string tablename = "dump"; //name of table

lock(SyncObject){lock(SyncObjects.TableSyncer){

    var table = project.Tables[tablename];

    //load data from table into variables
    for(int i=0; i<table.RowCount;i++){
        var row = table.GetRow(i).ToArray();
        if(project.Variables.Keys.Contains(row[0]) && row[0].StartsWith(prefix))
            if(!string.IsNullOrWhiteSpace(row[1]))
                project.Variables[row[0]].Value = row[1];
    }

    var varkeylist = project.Variables.Keys.Where(k=>k.StartsWith(prefix)).ToList();

    //make some manipulations with values and save them to next threads
    //in this example each value getting increased by 1
    table.Clear();
    varkeylist.ForEach(k=> {
        var newvalue = (int.Parse(project.Variables[k].Value)+1).ToString();
        table.AddRow(new List<string> {k, newvalue});
    });

}}
before run the snipet the in_ vars must have the default values in template or in the dump table
 
Последнее редактирование:

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 770
Благодарностей
1 182
Баллы
113
@LexxWork With this snippet you have to use files as well. Correct ? As I do not see any other way tables could be shared between threads...
 

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 707
Баллы
113

Nick

Client
Регистрация
22.07.2014
Сообщения
1 963
Благодарностей
796
Баллы
113
What's a maximum size of an in-memory globally available table with that it works so-so?
I mean, is it ok to make a global table and work with it from within several threads when its size is several megabytes?
And what is an overhead for metadata for such a table. I mean, if I read a 1 MB csv file into a in-memory table, how much RAM will it take there?
 

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 707
Баллы
113
There's no in built limitations.
Size of table in memory is 2-3 times bigger than size of original file
 

LexxWork

Client
Регистрация
31.10.2013
Сообщения
1 190
Благодарностей
786
Баллы
113

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)