Problem with IAsyncAction


  • This very simple code will throw an access violation. It looks to me like there may be a problem with reference counting, i.e. a Release() without AddRef() because if I don't capture any variable in the lambda, it will work.

    IAsyncAction^ PDF::CreateThumbnailAsync(String^ destinationPath, const Array<double>^ size) {
        return concurrency::create_async([this, destinationPath, size]() {

    Friday, June 15, 2012 5:03 PM

All replies

  • Follow-Up: extracting the double values from the array and capturing those like in

    IAsyncAction^ PDF::CreateThumbnailAsync(String^ thumbnailPath, const Array<double>^ size) {
      assert(size->Length == 2);
      double width = static_cast<UI32>(size[0]);
      double height = static_cast<UI32>(size[1]);
      return concurrency::create_async([this, thumbnailPath, width, height]() {

    Will make it work again. But since the values in the array are primitive types, I'm not sure what could be the problem. Any ideas?

    Monday, June 18, 2012 8:19 AM



    I test this codes without error.


    IAsyncAction^ testfunction(Array<int>^ size)
    	return concurrency::create_async([size](){
    			int a=9;

    I think you can delete the this in create_async, "this" will bind the class member into your task, maybe there is a same name with size in class.


    Best regards,


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, June 18, 2012 12:12 PM
  • The curious thing is that the error occurs even if I don't actually do anything with the variable - just capturing it is enough to cause an access violation.

    But the same-variable-hint is a good idea. There is a property "Size" - albeit with a capital 'S' - maybe this can cause a conflict?

    Monday, June 18, 2012 1:02 PM