******** プラットフォーム: Vista (ultimate または home/premium) では動作しません。その他の OS (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);}
}
};
}
ここで問題は何ですか...?