/// <summary> /// 清空回收站,这个方法同SHEmptyRecycleBin函数一样调用 /// </summary> /// <param name="hwnd">在调用SHEmptyRecycleBin期间,指向用来显示的对话框的父窗体的句柄 /// 可为NULL值 /// </param> /// <param name="rootpath">最大长度为260个字符的字符串,指定磁盘根目录或文件夹目录,可为null,则清空整个回收站的内容</param> /// <param name="dwFlags">SHERB枚举,可组合使用</param> /// <returns>成功返回0,否则为OLE定义的错误值</returns> public uint EmptyRecycleBin(IntPtr hwnd, string rootpath, SHERB dwFlags) { _rbState rvs = new _rbState(hwnd, rootpath, dwFlags); rvs.Revalue = 0x8000FFFF; long size, items; this.QuerySizeRecycleBin(out size, out items); if (size == 0) { return(rvs.Revalue); } lock (rvs) { Thread t = new Thread( new ParameterizedThreadStart(this.wrokThread)); t.SetApartmentState(ApartmentState.STA); t.Start(rvs); } /* Console.WriteLine("aaa");测试了,同一个对象实例,依次调用EmptyRecycleBin * 的任何一个重载,其顺序总是:先被调用的,总是先运行,后面的--排队等待 * 这样的原因是ewh是AUTO的,set之后,同样命名的对象就不会wait了 */ this.ewh.WaitOne(); this.ewh.Reset(); return(rvs.Revalue); }
internal _rbState(IntPtr hwnd, string rootpath, SHERB sherb) { this._hwnd = hwnd; this._rootpath = rootpath; this._sherb = sherb; _rv = 0; }
internal static extern Int32 SHEmptyRecycleBin ([MarshalAs(UnmanagedType.SysInt)]int windowHandleOwner, [MarshalAs(UnmanagedType.LPWStr)]String path, SHERB flags);
public static extern uint SHEmptyRecycleBinW( IntPtr hwnd, [In()] [MarshalAs(UnmanagedType.LPWStr, SizeConst = 260)] string rootpath, SHERB flags);
/// <summary> /// 清空回收站,这个方法同SHEmptyRecycleBin函数一样调用 /// </summary> /// <param name="hwnd">在调用SHEmptyRecycleBin期间,指向用来显示的对话框的父窗体的句柄 /// 可为NULL值 /// </param> /// <param name="rootpath">最大长度为260个字符的字符串,指定磁盘根目录或文件夹目录,可为null,则清空整个回收站的内容</param> /// <param name="dwFlags">SHERB枚举,可组合使用</param> /// <returns>成功返回0,否则为OLE定义的错误值</returns> public uint EmptyRecycleBin(IntPtr hwnd, string rootpath, SHERB dwFlags) { _rbState rvs = new _rbState(hwnd, rootpath, dwFlags); rvs.Revalue = 0x8000FFFF; long size, items; this.QuerySizeRecycleBin(out size, out items); if (size == 0) return rvs.Revalue; lock (rvs) { Thread t = new Thread( new ParameterizedThreadStart(this.wrokThread)); t.SetApartmentState(ApartmentState.STA); t.Start(rvs); } /* Console.WriteLine("aaa");测试了,同一个对象实例,依次调用EmptyRecycleBin 的任何一个重载,其顺序总是:先被调用的,总是先运行,后面的--排队等待 * 这样的原因是ewh是AUTO的,set之后,同样命名的对象就不会wait了 */ this.ewh.WaitOne(); this.ewh.Reset(); return rvs.Revalue; }
internal void ReSetState(IntPtr hwnd, string rootpath, SHERB sherb) { this._hwnd = hwnd; this._rootpath = rootpath; this._sherb = sherb; }
internal _rbState() { this._hwnd = IntPtr.Zero; this._rootpath = null; this._sherb = SHERB.SHERB_GENNERAL; }
SHEmptyRecycleBinW( IntPtr hwnd, [In()] [MarshalAs(UnmanagedType.LPWStr, SizeConst = 260)] string rootpath, SHERB flags);
ReSetState(IntPtr hwnd, string rootpath, SHERB sherb) { this._hwnd = hwnd; this._rootpath = rootpath; this._sherb = sherb; }