********平台:在 Vista(终极版或家庭/高级版)中它不起作用,其他操作系统(xp、windows7)它起作用***********
我在线程内使用 c++.net(或 c#.net)清空回收站。当我直接(没有线程)这样做时,它可以工作。但如果线程使用它不会。请看下面的代码片段:
namespace EmptyRecycleBin_C{
enum RecycleFlags
{
SHERB_NOCONFIRMATION = 0x00000001,
SHERB_NOPROGRESSUI = 0x00000002,
SHERB_NOSOUND = 0x00000004
};
public ref class Form1 : public System::Windows::Forms::Form{
[DllImport("Shell32.dll",CharSet=CharSet::Unicode)]
static System::UInt32 SHEmptyRecycleBin(IntPtr hwnd, String^ pszRootPath, RecycleFlags dwFlags);
private: void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
Thread^ th = gcnew System::Threading::Thread(gcnew ThreadStart(this, &Form1::doEmpty));
th->Start();
//this->doEmpty(); // this line works just fine
}
private: void doEmpty()
{
try{
SHEmptyRecycleBin(IntPtr::Zero, String::Empty, RecycleFlags::SHERB_NOCONFIRMATION);
}catch(Exception^ ex)
{Diagnostics::Debug::Write(ex->Message);}
}
};
}
这里有什么问题...?