I have this code:
private void timer1_Tick(object sender, EventArgs e)
{
#region BaseAddress
Process[] test = Process.GetProcessesByName(process); //Get process handle
if (test.Any())
{
int Base = test[0].MainModule.BaseAddress.ToInt32();
}
#endregion
//lots of other code blocks
}
I now want to take the region ‘BaseAddress’ out of the timer1_Tick control to make the code more efficient and have it run once at the beginning of the program. The other code in this control makes frequent use of the variable ‘Base’, what is the best way to make this globally accessible without having to go back through all the instances that use Base and do something like MyGlobals.Base, for example?
Lazy load the address into a static variable. It won’t initialize until you use it for the first time, then will remain in memory for the life of the application.
In some other part of the app…