Method to change default value from c#

  • Автор темы Автор темы lokiys
  • Дата начала Дата начала

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 922
Реакции
1 206
Баллы
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
 
Global variables?)
 
What exactly do you mean
 
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
 
Последнее редактирование:
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?
 
There's no in built limitations.
Size of table in memory is 2-3 times bigger than size of original file
 
@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...
Yes. This feature is a base for sharing local vars between threads.
 

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