Delete global variable in C#

Jack77

Новичок
Регистрация
25.10.2016
Сообщения
25
Благодарностей
3
Баллы
3
Hello guys.

Код:
var gbVar = project.GlobalVariables["stupidglobals", "globVar1"];
Are there anyway to delete that a global variable?

I'm using that for threads and unfortunately zennoposter gets that in memory after the process being executed :(

Thank you.
 
Последнее редактирование:

Jack77

Новичок
Регистрация
25.10.2016
Сообщения
25
Благодарностей
3
Баллы
3
Answering my own question, I think I can't do that. Had to find another way
 

Adigen

Client
Регистрация
28.07.2014
Сообщения
825
Благодарностей
651
Баллы
93

Jack77

Новичок
Регистрация
25.10.2016
Сообщения
25
Благодарностей
3
Баллы
3
Thanks for your answer bud. Really appreciate

But unfortunately, I'm quite sure set it to null is not the same from remove a variable.

Unless the code below is wrong, change a variable to null just changes its value null. Don't remove the variable. To remove, you will have to manually remove it from the project.

Код:
project.GlobalVariables.SetVariable("namespace", "globVar1", null);

Testing. In the code below:
Код:
var gbVar = project.GlobalVariables["namespace", "globVar1"];
If the variable exists, the code will return true

If the variable do not exist, this code will raise an error.

Set the variable to null, in case it exists, won't change the above behavior. The variable will, still, exist in memory.

Why that was important to me:

If you are using that as a flag for threads in zennoposter, only the first time you run it you will know who the first thread is, because the above code will raise an error. So, after get the first thread you create the variable to the remains threads. They won't raise errors and you will know they aren't the first thread.

If you run it again you won't know who the first thread is, since the variable is already created and you can't remove it from memory with code, only if you delete the project from the poster manager or restart zennoposter :(

Take a look at this thread: http://zennolab.com/discussion/threads/how-to-set-c-code-to-reset-globvar-to-0.21083/

It took me days trying all kind of solutions to overcome that. Then I realized that Globals are very unhandy and unstable. For me, it's better to sync important parts of the code with files.
 

Adigen

Client
Регистрация
28.07.2014
Сообщения
825
Благодарностей
651
Баллы
93
Thanks for your answer bud. Really appreciate

But unfortunately, I'm quite sure set it to null is not the same from remove a variable.

Unless the code below is wrong, change a variable to null just changes its value null. Don't remove the variable. To remove, you will have to manually remove it from the project.

Код:
project.GlobalVariables.SetVariable("namespace", "globVar1", null);

Testing. In the code below:
Код:
var gbVar = project.GlobalVariables["namespace", "globVar1"];
If the variable exists, the code will return true

If the variable do not exist, this code will raise an error.

Set the variable to null, in case it exists, won't change the above behavior. The variable will, still, exist in memory.

Why that was important to me:

If you are using that as a flag for threads in zennoposter, only the first time you run it you will know who the first thread is, because the above code will raise an error. So, after get the first thread you create the variable to the remains threads. They won't raise errors and you will know they aren't the first thread.

If you run it again you won't know who the first thread is, since the variable is already created and you can't remove it from memory with code, only if you delete the project from the poster manager or restart zennoposter :(

Take a look at this thread: http://zennolab.com/discussion/threads/how-to-set-c-code-to-reset-globvar-to-0.21083/

It took me days trying all kind of solutions to overcome that. Then I realized that Globals are very unhandy and unstable. For me, it's better to sync important parts of the code with files.
The problem is, that you don,t know what of threads is last.
So, if you want use global vars, you can use one that will contains count of runing threads, each thread in start increase it by 1, and decreased when end.
if var is null or 0, we have no threads running, so it,s new run.
 

Jack77

Новичок
Регистрация
25.10.2016
Сообщения
25
Благодарностей
3
Баллы
3
That is a nice solution Adigen.

I didn't do that because I was debugging and interrupting the poster at random moments. I was afraid about, in any of these interrupts, not allow the zennoposter to decrease the value. I'm not sure if, when you interrupt the script, the poster let the script reach at the BadEnd before the interruption. Got me?

So, end up using a pid file.

But that is a great solution once you don't need to touch the development anymore.

Thank you Adigen, have a great night man.
 

Adigen

Client
Регистрация
28.07.2014
Сообщения
825
Благодарностей
651
Баллы
93
That is a nice solution Adigen.

I didn't do that because I was debugging and interrupting the poster at random moments. I was afraid about, in any of these interrupts, not allow the zennoposter to decrease the value. I'm not sure if, when you interrupt the script, the poster let the script reach at the BadEnd before the interruption. Got me?

So, end up using a pid file.

But that is a great solution once you don't need to touch the development anymore.

Thank you Adigen, have a great night man.
Yes, when you break project, variable not decrease, so you can create one little project, that would reset it, and run this project after debug/breaking.
Or use files (think it,s more simple)
 

Jack77

Новичок
Регистрация
25.10.2016
Сообщения
25
Благодарностей
3
Баллы
3
I like the little project idea :-)

Do you mean different scripts share the same globals variables if they are in the same namespace?
 

Adigen

Client
Регистрация
28.07.2014
Сообщения
825
Благодарностей
651
Баллы
93

Jack77

Новичок
Регистрация
25.10.2016
Сообщения
25
Благодарностей
3
Баллы
3
That's interesting.

Thank you Adigen.
 

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