CancelSynchronousIo으로 WNetAddConnection2에 대한 전화를 취소하려고 시도했지만 실패했습니다.취소 동기화가 WNetAddConnection2와 함께 작동합니까?
CancelSynchronousIo에 대한 호출이 성공했지만 실제로 취소 된 것은 없습니다.
Windows 7 x64에서 실행되는 32 비트 콘솔 앱을 사용하고 있습니다.
누구든지 성공적으로이 작업을 수행 했습니까? 나는 바보 같은 짓을하고 있니? 래리 오스터에 따르면
DWORD WINAPI ConnectThread(LPVOID param)
{
NETRESOURCE nr;
memset(&nr, 0, sizeof(nr));
nr.dwType = RESOURCETYPE_ANY;
nr.lpRemoteName = L"\\\\8.8.8.8\\bog";
// result is ERROR_BAD_NETPATH (i.e. the call isn't cancelled)
DWORD result = WNetAddConnection2(&nr, L"pass", L"user", CONNECT_TEMPORARY);
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
// Create a new thread to run WNetAddConnection2
HANDLE hThread = CreateThread(0, 0, ConnectThread, 0, 0, 0);
if (!hThread)
return 1;
// Retry the cancel until it fails; keep track of how often
int count = 0;
BOOL ok;
do
{
// Sleep to give the thread a chance to start
Sleep(1000);
ok = CancelSynchronousIo(hThread);
++count;
}
while (ok);
// count will equal two here (i.e. one successful cancellation and
// one failed cancellation)
// err is ERROR_NOT_FOUND (i.e. nothing to cancel) which makes
// sense for the second call
DWORD err = GetLastError();
// Wait for the thread to finish; this takes ages (i.e. the
// WNetAddConnection2 call is not cancelled)
WaitForSingleObject(hThread, INFINITE);
return 0;
}
I/O 작업, 드라이버 IRP를 취소합니다. WNetAddConnection2는 매우 다른 동물입니다. –
원격 서버에서 FindFirstFile을 수행하면 먼저 연결을 시도하는 것을 차단합니다. 아마도 WNetAddConnection2와 동일한 내부 코드와 IRP를 사용했을 것입니다. 어떤 근본적인 차이도없는 것 같지만, 이전은 취소 가능하고 후자는 분명히 아닙니다. 내가 놓친 게 있니? – arx
(당신은 @ 한스 말을 잊어 버렸습니다.) UNF 경로에 대한 FindFirstFile의 경우 FindFirstFile 작업 자체 만 취소되고 네트워크 연결 시도 자체가 잘 완료 (또는 시간 초과) 될 수 있습니다. 그 다음 버렸다. –