locked
Nested load file failed

    Question

  • I want to collect a lot of files. This files are located in several nested folders. I have in this directory about 1200 files (1.2 GB). The root folder are located in Music-folder. I try to open any file and load the content in the RAM to perform further operations at this content. But the process freezes itself after a while. Then, I can no longer start my app. The Visual Studio can not it even. I always have to restart the Windows.

    If there are fewer files (54 files, 43 MB), then it works! Do I something wrong?

    Here is my code:

    // First I press the button:

    void HarddriveLimit::MainPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
    {
     auto spFolder = KnownFolders::MusicLibrary;
     auto spGetFolder = spFolder->GetFolderAsync(L"Soundpool"); // this is a root folder with several nested subfolders
     spGetFolder->Completed = ref new Windows::Foundation::AsyncOperationCompletedHandler<StorageFolder^>([this](Windows::Foundation::IAsyncOperation<Windows::Storage::StorageFolder^>^ spValue)
     {
      if(spValue->Status == AsyncStatus::Completed)
      {
       auto spFolder = spValue->GetResults();
       GatherLoops(spFolder);
      }
     });
     spGetFolder->Start();
    }

    // This function gathers all files from the given folder.

    void HarddriveLimit::MainPage::GatherAudios(StorageFolder^ spFolder)
    {
     auto spGetFiles = spFolder->GetFilesAsync();
     spGetFiles->Completed = ref new AsyncOperationCompletedHandler<IVectorView<IStorageFile^>^>([=](IAsyncOperation<IVectorView<IStorageFile^>^>^ operation)
     {
      if(operation->Status == AsyncStatus::Completed)
      {
       auto files = operation->GetResults();
       for(unsigned int i = 0; i < files->Size; i++) // loop over all files
       {
        auto spFile = (StorageFile^)files->GetAt(i);
        auto nextOperation = spFile->OpenForReadAsync();
        auto fileSize = spFile->Size;
        nextOperation->Completed = ref new Windows::Foundation::AsyncOperationCompletedHandler<IInputStream^>([=](Windows::Foundation::IAsyncOperation<IInputStream^>^ thisOperation)
        {
         if(thisOperation->Status == Windows::Foundation::AsyncStatus::Completed)
         {
          DataReader^ reader = ref new DataReader(thisOperation->GetResults());
          auto nextOperation2 = reader->LoadAsync(fileSize);
          nextOperation2->Completed = ref new Windows::Foundation::AsyncOperationCompletedHandler<uint32>([=](Windows::Foundation::IAsyncOperation<uint32>^ thisOperation)
          {
           if(thisOperation->Status == Windows::Foundation::AsyncStatus::Completed)
           {
            array<unsigned char>^ fileData = ref new array<unsigned char>(fileSize); // I get a buffer with the file content.
            reader->ReadBytes(fileData);
            CallbackF(fileData); // easy callback to the GUI
           }
          });
          nextOperation2->Start();
         }
        });
        nextOperation->Start();
       }
      }
     });
     spGetFiles->Start();
    }

    // this function gathers all subfolders from the given folder

    void HarddriveLimit::MainPage::GatherLoops(StorageFolder^ spFolder)
    {
     GatherAudios(spFolder);

     auto spFolders = spFolder->GetFoldersAsync();
     spFolders->Completed = ref new AsyncOperationCompletedHandler<IVectorView<IStorageFolder^>^>([=](IAsyncOperation<IVectorView<IStorageFolder^>^>^ spOperation)
     {
      if(spOperation->Status == AsyncStatus::Completed)
      {
       auto folders = spOperation->GetResults();
       for(unsigned int i = 0; i < folders->Size; i++)
       {
        auto spSub = folders->GetAt(i);
        GatherLoops((StorageFolder^)spSub);
       }
      }
     });
     spFolders->Start();
    }

    // easy print the current read size

    void HarddriveLimit::MainPage::CallbackF(array<unsigned char>^ fileData)
    {
     unsigned char* pBuffer = fileData->Data;
     unsigned __int64 nSize = fileData->Length;

     m_nTotalSize += nSize;

     wchar_t szDig[32];
     ::StringCchPrintfW(szDig, sizeof szDig, L"%I64u", m_nTotalSize);
     m_stcText->Text = ref new String(szDig);
    }

    Wednesday, December 7, 2011 3:19 PM

Answers

  • Turns out this is a bug in the Developer Preview. Thanks so much for this feedback! This should work as expected in the next beta release.

     

    Thanks,

    -David

    Tuesday, December 20, 2011 6:19 PM
    Moderator

All replies

  • Do you see the process listed in TaskManager when in this problem state? Is there anything unusual like high CPU or high memory at the time? Is it utilizing any CPU at all?

     

    If the process is listed in TaskManager, I'd like to take a look at a dump of the process to see what state it is in. On the Details tab in TaskManager, right-click the process and select 'Create Dump File'.

     

    Contact me for details on uploading the file. I can be reached at:

    Davidlam

    AT

    Microsoft

    DOT

    COM

     

    Thanks,

    -David

     

     

    Thursday, December 8, 2011 2:45 AM
    Moderator
  • Turns out this is a bug in the Developer Preview. Thanks so much for this feedback! This should work as expected in the next beta release.

     

    Thanks,

    -David

    Tuesday, December 20, 2011 6:19 PM
    Moderator