Ive thu hẹp xuống phương pháp này nhưng tôi không hiểu tại sao nó khóa tệp. Tôi tin rằng bạn có thể sử dụng một cái gì đó nhưtại sao mã này khóa tệp của tôi?
using(something)
{
//do stuff here
}
Nhưng không chắc chắn A) giải quyết vấn đề hay B) là cách chính xác nếu có.
bất kỳ ý tưởng nào?
[DllImport("user32.dll", CharSet = CharSet.Auto)]private static extern Int32 SystemParametersInfo(UInt32 action, UInt32 uParam, String vParam, UInt32 winIni);
private static readonly UInt32 SPI_SETDESKWALLPAPER = 0x14;
private static readonly UInt32 SPIF_UPDATEINIFILE = 0x01;
private static readonly UInt32 SPIF_SENDWININICHANGE = 0x02;
private void SetWallpaper(string path)
{
try
{
Image imgInFile = Image.FromFile(path);
imgInFile.Save(SaveFile, ImageFormat.Bmp);
SystemParametersInfo(SPI_SETDESKWALLPAPER, 3, SaveFile, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
}
catch
{
MessageBox.Show("error in setting the wallpaper");
}
}
#
đang cập nhật
private void SetWallpaper(string path)
{
if (File.Exists(path))
{
Image imgInFile = Image.FromFile(path);
try
{
imgInFile.Save(SaveFile, ImageFormat.Bmp);
SystemParametersInfo(SPI_SETDESKWALLPAPER, 3, SaveFile, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
}
catch
{
MessageBox.Show("error in setting the wallpaper");
}
finally
{
imgInFile.Dispose();
}
}
}
Tôi cũng sẽ ném vào: if (File.exists (path)) {..} – Nippysaurus
@Nippysaurus: Tôi muốn SetWallpaper() tự ném. –
tôi đoán câu hỏi của tôi là khác nhau như thế nào khi phương thức được chạy xong. sao hình ảnh không được tự động xử lý sau khi hoàn thành? – Crash893