Delete global variable in C#

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

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.
 
Последнее редактирование:
Answering my own question, I think I can't do that. Had to find another way
 
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.
 
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.
 
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.
 
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)
 
I like the little project idea :)

Do you mean different scripts share the same globals variables if they are in the same namespace?
 
That's interesting.

Thank you Adigen.
 

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