This is a migrated thread and some comments may be shown as answers.

Bug variable was declared outside lock context block

1 Answer 20 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Blamara
Top achievements
Rank 1
Blamara asked on 06 Apr 2015, 12:13 AM

pretty formating is little buggy, maybe you should leave it as is ;)

if we declare variable outside lock, then do something inside lock, and later invoke it on another thread decompiled code is broken.

Original code:

class OutsideLock : UserControl
{
  ulong IamClassMember = 0;
  private void DrawBackgroundAsync()
  {
    ulong IamOutsideLock;
    lock (this)
    {
      ++this.IamClassMember;
      IamOutsideLock = this.IamClassMember;
    }
    // Util.DoAllDrawEvents(this.myImage.Dispatcher);
    int width = (int) Math.Round((double)this.Width);
    int height = (int) Math.Round((double)this.Height);
    ThreadPool.QueueUserWorkItem((WaitCallback) (param0 => this.DoDrawWork(IamOutsideLock, width, height)));
  }
 
  private void DoDrawWork(ulong iDraw, int width, int height)
  {
    // bla
  }
}

Decompiled code:
internal class OutsideLock : UserControl
{
    private ulong IamClassMember;
 
    public OutsideLock()
    {
    }
 
    private void DoDrawWork(ulong iDraw, int width, int height)
    {
    }
 
    private void DrawBackgroundAsync()
    {
        lock (this)
        {
            OutsideLock iamClassMember = this;
            iamClassMember.IamClassMember = iamClassMember.IamClassMember + (long)1;
            ulong num = this.IamClassMember;
        }
        int num1 = (int)Math.Round((double)base.Width);
        int num2 = (int)Math.Round((double)base.Height);
        ThreadPool.QueueUserWorkItem((object param0) => this.DoDrawWork(num, num1, num2));
    }
}

as you can see there is no variable declaration before lock context block, instead its moved inside lock context block.
resulting in error in compiler since call to DoDrawWork is outside lock context block:
>> error CS0103: The name 'num' does not exist in the current context

also what is that italic text!?
what have you done with increment?

1 Answer, 1 is accepted

Sort by
0
Accepted
Alexander
Telerik team
answered on 07 Apr 2015, 02:39 PM
Hi Blamara,

Thank you for letting us know about this problem.

The bug is added to our backlog and will be fixed as soon as possible.

Please, update regularly and stay tuned.

Regards,
Alexander
Telerik
Tags
General Discussions
Asked by
Blamara
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or