locked
how to use create_task ??

    Question

  • hi~ i am software engineer

    i make file control app in metro style app. but i don't konw how to use create_task 

    for example 

     create_task(openPicker->PickSingleFileAsync()).then([](file)
    {
    if (file)
    {

    create_task(file->CopyAsync(ApplicationData::Current->TemporaryFolder, file->Path, NameCollisionOption::GenerateUniqueName)).then([](StorageFile^ fileTemp)
    {
    if(fileTemp)
    {

    }

    });
    // i want use fileTemp or return fileTemp
    }
    });
    i want use file or return file

     is there method ?? 

    it is my first experience so help me ~ thank you!!


    jang

    Friday, July 6, 2012 4:58 AM

Answers

  • Hi

    Not sure what is the problem. First, include <ppltasks.h> header; create_task is in the Concurrency namespace.

    Use 'file' in the provided continuation. Something like:

    	FileOpenPicker^ openPicker = ref new FileOpenPicker();
    	openPicker->ViewMode = PickerViewMode::Thumbnail;
    	openPicker->SuggestedStartLocation = PickerLocationId::PicturesLibrary;
    	openPicker->FileTypeFilter->Append(".jpg");
    
    	create_task(openPicker->PickSingleFileAsync()).then([](StorageFile^ file) 
    	{ 
    		if (file) 
    		{ 
    			// do something with a file
    		} 
    		else 
    		{ 
    			// cancelled
    		} 
    	});

       And don't forget to declare the necessary capabilities in your app manifest.
    Friday, July 6, 2012 11:34 AM

All replies

  • Hi

    Not sure what is the problem. First, include <ppltasks.h> header; create_task is in the Concurrency namespace.

    Use 'file' in the provided continuation. Something like:

    	FileOpenPicker^ openPicker = ref new FileOpenPicker();
    	openPicker->ViewMode = PickerViewMode::Thumbnail;
    	openPicker->SuggestedStartLocation = PickerLocationId::PicturesLibrary;
    	openPicker->FileTypeFilter->Append(".jpg");
    
    	create_task(openPicker->PickSingleFileAsync()).then([](StorageFile^ file) 
    	{ 
    		if (file) 
    		{ 
    			// do something with a file
    		} 
    		else 
    		{ 
    			// cancelled
    		} 
    	});

       And don't forget to declare the necessary capabilities in your app manifest.
    Friday, July 6, 2012 11:34 AM
  • Just a couple of points for this explanation marked answered.  There isn't enough information for a new C++ programmer to understand the answer.

    For instance:

    The documentation is never "complete", for instance the software engineer is asking how to fix his problem.  The "answer" is good, but not complete for new C++ programmers, here is the problem many new C++ users are having:

    • Where to put things, especially when using the supplied templates, which with XAML should could be assumed when answering questions like this.
    • In the answer the clause: "First, include <ppltasks.h> header;..." does indicate where to correctly place the include statement. 

    First off, if you put the #include <ppltasks.h> in the source file, for instance the MainPage.xaml.cpp, which many new programmers will do.  The correct place is the pch.h file, which is where the #include <ppltasks.h> should be placed.  Otherwise the new programmer will likely be confused about where to place the parallel programming header.  If you place the #include <ppltasks.h> in the source file you get a number of error statements that can be confusing.

    With the re-introduction of C++, many of the programmers are looking to use C++, but aren't familiar with the use of the pch.h, and where to place include statements to get them to work.  It is frustrating for the returning or new C++ programmer. 

    The answer is good, and rightly should be marked as the answer, but it is not complete from the point of view of beginning or returning programmer.  Hopefully this appendix is helpful for new or returning C++ programmer.


    Sam Stokes

    Thursday, September 13, 2012 3:39 AM