class A
{
TypeX PropertyX;
void SomeMethod()
{
using (DisposableType y = new DisposableType())
{
PropertyX = y.GetX();
}
}
}
What happens to PropertyX when Y is being disposed? Would I rather do this, if I don't know what is being disposed with Y?
class A : IDisposable
{
TypeX PropertyX { get; set;}
DisposableType Y { get; set; }
void SomeMethod()
{
using (Y = new DisposableType())
{
PropertyX = Y.GetX();
}
}
void Dispose()
{
Y.Dispose();
}
}
MainWindowand its value will be preservedusingisn't to dispose everything within the brackets, but just the used instance, in your case the instance ofUIA2Automation. SoMainWindowstays untouched, however the providedautomationwill be disposed and thus the member within your window (if it has such a member).MainWindowandautomation? DoesMainWindowcare aboutautomationat all?