locked
Trying to share a link recieved from the concurrency using in windows 8

    Question

  • I am trying to implement the share source feature in a c++ windows 8 metro sample. I am basically trying to share a link which is obtained from the concurrency but it is throwing an error as access violation. I am posting the code below though this is not the actual code this also does not work.

    	concurrency::task<String^>([this,&Uritosahre](){
    
    		Uritosahre="http://www.codeproject.com/Articles/333411/A-Study-of-Windows-8-Contracts-why-what-and-how";
    		return Uritosahre;
    	});
    
    	if(!Uritosahre->IsEmpty()){
    		Uri^ dataPackageUri = ValidateAndGetUri(Uritosahre);
    		if (dataPackageUri != nullptr)
    		{
    			auto requestData = request->Data;
    			requestData->Properties->Title = TitleInputBox->Text;
    
    			// The description is optional.
    			auto dataPackageDescription = DescriptionInputBox->Text;
    			if (dataPackageDescription != nullptr)
    			{
    				requestData->Properties->Description = dataPackageDescription;
    			}
    			requestData->SetUri(dataPackageUri);
    			succeeded = true;
    		}
    	}
    	else
    	{
    		request->FailWithDisplayText("Enter the link you would like to share and try again.");
    	}
    	return succeeded;
    }
    Please enlighten me where I am doing this wrong

    I have tried using the auto requestData = request->Data;
    requestData->Properties->Title = TitleInputBox->Text;

    // The description is optional.
    auto dataPackageDescription = DescriptionInputBox->Text;
    if (dataPackageDescription != nullptr) in the .then block as well but it trows same exception.
    • Edited by Ramya SJ Monday, September 24, 2012 3:00 PM
    Monday, September 24, 2012 2:49 PM

All replies

  • Where exactly do you get the exception?

    Is it when referencing Uritosahre? When and how do you define it?

    I suspect that Uritosahre is a local variable and the crash

    You need to be careful when capturing a variable by reference that the variable will still be alive when the lambda is called. This won't be the case for local variables, since the enclosing function may finish before the task has completed.

    I'm also not sure what exactly your function is trying to do. Why are you initializing Uritosahre in a task? Is the real code initializing it from an Async function? If so, you probably want to do the rest if the function in a continuation from the task so it gets called after the initialization task has completed instead of simultaneous or before. 

    --Rob

     

    Monday, September 24, 2012 10:20 PM
    Owner
  •  I am getting exception in the concurrency block. It is with respect to the uritosahre and it chrashes. I am very new to c++ and have no idea what is going on in this. If I use a local variable then the datatransfer event wont work in the concurrency . I tried with that. The urisahre is filled with the content from the concurrency after the datatransfer event is completed. Please provide a solution so that I can make it wait or something to ensure that the event is completed only after concurrency is completed.
    Tuesday, September 25, 2012 4:41 AM
  • why wont
    request->Data->SetUri(dataPackageUri);

    work inside the concurrency why does it throw access denied exception
    • Marked as answer by Ramya SJ Tuesday, December 18, 2012 9:53 AM
    • Unmarked as answer by Ramya SJ Tuesday, December 18, 2012 9:53 AM
    Wednesday, September 26, 2012 5:12 AM