Alternatives
Members may post updates or alternatives to this current article in order to show different
approaches or add new features.
18 Jan 2013z3ngew 4 alternatives
Hello everyone,How can i use a method only one time at the beginning of the code, knowing that this method is part of an event that runs alwaysApplication.Idle += Myevent;Thanks in advance,z3ngew
Here is one way to only run a method in code once. As you can see it uses a bool flag and a for loop to simulate multiple times being ran. After the first time the OnlyOnce method executes it sets the flag to true signifying its been ran and will not run within that for loop anymore.public...
18 Jan 2013PIEBALDconsult
It depends. Can you make it a static constructor?A problem with the flag method is that some code could clear your flag (via Reflection if necessary) and run the method again. To make it a little more secure you could put the special method in separate class.I haven't read all of...
18 Jan 2013Sergey Alexandrovich Kryukov
You can do it in a very simple way, but do it over, again and again. Or, you can do it in a very universal way.Nearly everyone knows the simple way, but, to best of my knowledge, the universal way is happened to be only mine. It's is very exotic but fully legitimate and reliable, as it is...