You can limit the scope of '
p
' inside your function:
private void Whatever() {
DoStuffHere();
{
var p = this.StatusProgressBar;
p.IsIndeterminate = false;
p.[etc]
}
DoMoreHere();
}
Notice the open and close braces - they create a scope that '
p
' will not be leaked from.
Personally, I like your idea better - but it *is* possible to limit scope within a function.