PRB: ???? ????? ????? ERROR_SHARING_VIOLATION ??? ??? ???? CreateFile

?????? ????????? ?????? ?????????
???? ???????: 316609 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

???????

??? ??? ??? ?? ????? FILE_SHARE_READ ? ????? FILE_SHARE_WRITE ?? ???? ?????? CreateFile ????? ?????? ????? ????? ???????:
ERROR_SHARING_VIOLATION (??? ????? 32)

?????

????? ??? ?????? ??? ???????.

??????? ????

??? ??? ??? ???????? ?????? CreateFile ?? ??? ???? ?????? CreateFile ??????? ???? ?? ????? ??? ??? ????? ???? ???? ?????? ?? ??????. ??? ??? ??? ????? ??? ?? ??? ????? ???? "? ???? ???????? ?????? ???? ?? ??????? ?? ???? ?? ????? ?????? ??? ????? ?? ??? ?????. ???? ?????? ?????? ??????? ????? ??????? ?????? ?????? ???? ???? ??? ???????. ???? ?????? ?????? ??????? ?????? ????????? ?? ??? ?????? (??? ???? ????????? ?????) ???? ???? ??? ???????.

???? ??????? Microsoft Windows ?? ???? ????? ???????? preemptive ? ? ???? ???? ???? ?????? ?? ????????? ???? ???? ?? ??? ?????. ??? ?? ???? ?? ????? ???? "???" ??? ?? ??? ???????? ??? ???? ???? ??? ?????? ?? ??? vying ??????? ?? ???????? ??????. ??? ?? ???? ?????? ??????? ???? ?? ???? ???? ?????? ??????. ?? ???? ???? ???????? ?? ????? ??? ??????? ??? ???? ?? ?????? ??????? ??????. ???? ?????? ?????? ?????? ?????? ??? ?????? ??????? ??????? ?? ??? ?????. ??? ?????? ??? ??????? ?????? ??? ??????? ???????? ??? ?????? ???? ????? ??????? ?? ???????? ??????.

???? ????? ?? ??????? ??????? ERROR_SHARING_VIOLATION:
  • ???? ?????? ?? ????????? ???? ?????? ??? ???? ??? ????? (????? ???????? ???????? ???????). ??? ??????? ??????? ??? ????? ?????? ??? ?????? ?? ????? ????? ???? ????? ?????? ??? ??? ????? ??????. ??? ???? ??????? ?? ????? ??? ????? ????? ???? ????? ???? ?????? ??????? ??? ????? ? ??? ??? ?????? ????? ?????? (FILE_SHARE_READ).
  • ????? ??? ?????? ????? ??? ??????? ????? ?? ? ?? ????? ?? ???? ????? ??? ???? ????? ???????. ?? ??? ?????????? ?? ???????? ?????? ????? ??? ???? ????? ?????? ????.
???? ??????? ?????? ?????? ??? ?????? ???????? ??? ????????? ?? ????? ????? ????????? ?? ?????? ??? ???? ????? ??? ????? ??? ????? ????? ?????. ????? ????? ????? ??? ??? ?????? ??? ?? ????? ?????? ?????? ? ???? ???????? ?? ???? ?????? ?? ??????. ????? ???? ??? ??????? ???? ??? ?? ???? ??? ?????? ?? ???? ??? ???? ??????? ??? ?????. ??? ??? ???????? ???? ??? ???? ??? ???? ??????. ?????? ??? ????? ?????? ?? ????? ??????? ?? ??? ??????? ?????.

??? ?????? ?? ?? ??????? ??????? ???????? ???? ?????? ???? ?????. ??? ??? ??? ????? ???? ??? ?? ?????? ???? ?????? ?? ?????? ????? ?? ??? ???? ??? ?? ???? ??? ?????? ?????? ?? ???? ??? ???? ??????. ????? ?????? ???? ???????? ???? ????? ????? ??????. ?? ????? ??? ????? ??? ???? ????? ???????? ??? ????? ????? ?????.

???? ????? ????????? ???????? ?????? ??? ???????:
#define MAXRETRIES  5
#define RETRYDELAY  250

HANDLE  hFile     = INVALID_HANDLE_VALUE
DWORD   dwRetries = 0;
BOOL    bSuccess  = FALSE;
DWORD   dwErr     = 0;

do
{
    hFile = CreateFile( szFile,
                        GENERIC_READ,
                        FILE_SHARE_READ | FILE_SHARE_WRITE,
                        NULL,
                        OPEN_EXISTING,
                        FILE_ATTRIBUTE_NORMAL,
                        NULL);
    if ( INVALID_HANDLE_VALUE == hFile )
    {
        dwErr = GetLastError();

        if ( ERROR_SHARING_VIOLATION == dwErr )
        {
            dwRetries += 1;
            Sleep(RETRYDELAY);
            continue;
        }
        else
        {
            // An error occurred.
            break;
        }
    }

    bSuccess = TRUE;
    break;
} while ( dwRetries < MAXRETRIES );

if  ( bSuccess )
{
    // You succeeded in opening the file.
}
else
{
    // Failure occurs. Do graceful error handling.

    // Here, you must notify the user of the failure.

MessageBox( NULL,
            "Tried to update data file but it was already in use",
            "Update error...",
            MB_OK | MB_ICONSTOP );

    // You also want to put the software back in the state it was in
    // on entrance of the current function, as if the user had never
    // tried to do the update.

    // This may also require deallocating any resources that were
    // allocated because of this operation.
}
				
???? ??? ??????? ????? ??????? ??? ?????? ?????? ????? ??? ????? ?????? ?????. ?? ???? ??? ?????? ??????, ???? ??? ?? ???? ??????? ??? ??? ?????? ????? ?????? ?? ???? ??? ????. ??? ??? ????????? ?? ???? ???? ?? ???????? ??? ????? ?? ????????? ?? ???? ?????? ??? ????? ???????? ?? ??????. ???? ?? ????? ???? ????? ???????? ????? ???? ?? ??????. ?? ???? ????? ??? ?????? ??? ????? (????????? ?? ????? ?????? ???? ?????) ? ?????? ???????? ?? ???? ??? ?? ?????? ?? ????? ?????.

???????

???? ???????: 316609 - ????? ??? ??????: 30/????/1427 - ??????: 1.2
????? ???
  • Microsoft Win32 ????? ????? ???????
????? ??????: 
kbmt kbfileio kbkernbase kbprb KB316609 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????316609
????? ??????? ?? ????? ???? ?? ????? ???????
?? ????? ????? ?????? ???? ???? ???? ??? ??????? ??? ?? ? ?? ??? ??????? Microsoft ??? ????? ??? ??????? ????? ?????? ?????

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com