I am using ReSharper with C#/VS2010. I am running a seperate thread that needs to open a form to display some information to the user on the main UI thread. My code was this (which works great):
this.Invoke(new MethodInvoker(delegate()
{
DisplayDownload form2 = new DisplayDownload();
form2.TopMost = true;
form2.Show();
}));
ReSharper wanted to change it to this and I let it (but the following code does not display the form at all):
this.Invoke(new MethodInvoker(delegate()
{
using (var form2 = new DisplayDownload {TopMost = true})
{
form2.Show();
}
}));
The form never displays anymore with the ReSharper modified code. It works fine if I go back to the old code.
Why does it not work after ReSharper changed it? Can someone please explain it to me what is causing the modified code to not display the form anymore?
I believe its due the USING keyword. Considering that Show() is not blocking call, after that the program leaves using statement and Dispose() of the form called.
Regards.