并非虚构... (一笑之)
作者:Chris Sells
译者:荣耀
我的一个朋友在微软源码中意外发现了如下代码:
//Function: RunCommandEx
//Synopsis: runs the given command in the current session, more robust
// than RunCommand
//Arguments: none
//Returns: S_OK if success
//History: October 3, 2000 - created [name withheld to protect the guilty]
HRESULT RunCommandEx(LPCWSTR szCmdLine)
{
DWORD dwTry = 0;
HRESULT hResult = S_OK;
//try run command 3 times at most
while (dwTry<4)
{
hResult = RunCommand(szCmdLine);
if (hResult!=E_FAIL)
{
//we succeeded
break;
}
dwTry++;
}
if (dwTry==4)
{
ATLTRACE(L"COuld start the command even we tried 4 times/n");
//译注:或许Chris的本意是
//ATLTRACE(L"Couldn't start the command even we tried 4 times/n");
ASSERT(FALSE);
}
return hResult;
}
这并非我所指的强健,但也不错...
博客讲述朋友在微软源码中发现RunCommandEx函数代码,该函数可在当前会话运行给定命令,比RunCommand更健壮,最多尝试运行命令3次,若4次都失败会输出提示并断言。
87

被折叠的 条评论
为什么被折叠?



