Код: Выделить всё
fetchPathContentsКод: Выделить всё
struct APP_FETCH_THREAD_SPEC {
std::wstring path;
std::wstring timestamp;
};
< /code>
// On any new directory selection
APP_FETCH_THREAD_SPEC* customData = new APP_FETCH_THREAD_SPEC({
globalCurrentPath/* Current Path is in a global var*/,
timestamp });
HANDLE hThread = CreateThread(NULL/*default security attrs*/,
0/*default stack size*/,
Thread_Fetch_Func,
customData,
0/*default creation flags*/,
NULL);
// ... Another thread like this will be created on any directory click
< /code>
Thread Function:
DWORD WINAPI Thread_Fetch_Func(LPVOID lParam) {
// Obtain custom data
APP_FETCH_THREAD_SPEC* customData = (APP_FETCH_MAIN_THREAD_SPEC*)lParam;
// Call inner fetchPathContents()
std::vector results = fetchPathContents(customData->path);
// Finalize/close thread afterwards, cleanup, etc.
// ...
}
< /code>
Actual inner fetchPathContentsКод: Выделить всё
std::vector fetchPathContents(const std::wstring& inputPath) {
WIN32_FIND_DATA findData;
HANDLE hFind = INVALID_HANDLE_VALUE;
std::wstring full_path = inputPath + L"\\*";
hFind = FindFirstFile(full_path.c_str(), &findData);
do {
// ... etc. normal Win32 file-listing process for a given path ...
} while (FindNextFile(hFind, &findData) != 0);
//...
return results;
}
< /code>
Somewhere in fetchPathContents[*] Как только запускается поток № 2, FetchPathcontents < /code> исключительно обрабатывает, что второй список (5 файлов), и никогда не переключается на первое привод (I.E. function);
Когда поток № 2 заканчивается и поток возвращается в FetchPathContents Для оставшихся файлов 1 -й пути значение параметров inputPath от Thread #2 (PATH2)! Значение параметра повреждено. < /P>
< /li>
< /ol>
Таким образом, существует некоторая проблема с тем, что функция внутренней библиотеки не используется в асинхронном манере из каждой из основной внешней функции потоков. Я ожидаю, что внутренняя функция fetchPathContents будет изменен между вызовами потока и с правильным значением InputPath для каждого.
Подробнее здесь: https://stackoverflow.com/questions/797 ... -param-val
Мобильная версия