Resharper Extract Method safety

I have method
           bool doCallback = true;
           var thread1 = new Thread((state =>
            {
                Thread.Sleep(1000);
                lock (syncRoot)
                {
                    if (doCallback)
                    {
                        doCallback = false;
                        Console.WriteLine("Callback invoked");
                    }
                }
            }));

            var thread2 = new Thread((state =>
            {
                lock (syncRoot)
                {
                    if (doCallback)
                    {
                        doCallback = false;
                        Console.WriteLine("Callback invoked");
                    }
                }

            }));
            thread1.Start();
            thread2.Start();
            Console.ReadKey();

It writes:
Callback invoked

After using Extract method refactoring 2 times in Resharper 5 and VS2010 I get:

            bool doCallback = true;

            var thread1 = new Thread((state =>
                                          {
                                              Thread.Sleep(1000);
                                              lock (syncRoot)
                                              {
                                                  DoCallback1(doCallback);
                                              }
                                          }));

            var thread2 = new Thread((state =>
            {
                lock (syncRoot)
                {
                    DoCallback2(doCallback);
                }
            }));

            thread1.Start();
            thread2.Start();

            Console.ReadKey();
        }

        private static void DoCallback2(bool doCallback)
        {
            if (doCallback)
            {
                doCallback = false;
                Console.WriteLine("Callback invoked");
            }
        }

        private static void DoCallback1(bool doCallback)
        {
            if (doCallback)
            {
                doCallback = false;
                Console.WriteLine("Callback invoked");
            }
        }


It writes:
Callback invoked
Callback invoked

Resharper really should insert ref keyword, but it does not.

Is it my mistake or concern of Resharper safety?



Attachment(s):
ResharperSafety.zip
1 comment
Comment actions Permalink

Hello Dzmitry

     Thank you for reporting! We already have a similar issue logged in our tracker: http://youtrack.jetbrains.net/issue/RSRP-105944, so you're welcome to vote for it.

Andrey Serebryansky

Support Engineer

JetBrains, Inc

http://www.jetbrains.com

"Develop with pleasure!"

0

Please sign in to leave a comment.