C# 利用ResourceWriter写文件 如何判断写完成
答案:2 悬赏:30
解决时间 2021-02-16 15:58
- 提问者网友:剪短发丝
- 2021-02-16 02:54
C# 利用ResourceWriter写文件 如何判断写完成
最佳答案
- 二级知识专家网友:青春如此荒謬
- 2021-02-16 03:35
利用Windows API
C# code
using System.IO;
using System.Runtime.InteropServices;
[DllImport("kernel32.dll")]
public static extern IntPtr _lopen(string lpPathName, int iReadWrite);
[DllImport("kernel32.dll")]
public static extern bool CloseHandle(IntPtr hObject);
public const int OF_READWRITE = 2;
public const int OF_SHARE_DENY_NONE = 0x40;
public readonly IntPtr HFILE_ERROR = new IntPtr(-1);
private void button1_Click(object sender, EventArgs e)
{
string vFileName = @"c:\temp\temp.bmp";
if (!File.Exists(vFileName))
{
MessageBox.Show("文件都不存在,你就不要拿来耍了");
return;
}
IntPtr vHandle = _lopen(vFileName, OF_READWRITE | OF_SHARE_DENY_NONE);
if (vHandle == HFILE_ERROR)
{
MessageBox.Show("文件被占用!");
return;
}
CloseHandle(vHandle);
MessageBox.Show("没有被占用!");
}
C# code
using System.IO;
using System.Runtime.InteropServices;
[DllImport("kernel32.dll")]
public static extern IntPtr _lopen(string lpPathName, int iReadWrite);
[DllImport("kernel32.dll")]
public static extern bool CloseHandle(IntPtr hObject);
public const int OF_READWRITE = 2;
public const int OF_SHARE_DENY_NONE = 0x40;
public readonly IntPtr HFILE_ERROR = new IntPtr(-1);
private void button1_Click(object sender, EventArgs e)
{
string vFileName = @"c:\temp\temp.bmp";
if (!File.Exists(vFileName))
{
MessageBox.Show("文件都不存在,你就不要拿来耍了");
return;
}
IntPtr vHandle = _lopen(vFileName, OF_READWRITE | OF_SHARE_DENY_NONE);
if (vHandle == HFILE_ERROR)
{
MessageBox.Show("文件被占用!");
return;
}
CloseHandle(vHandle);
MessageBox.Show("没有被占用!");
}
全部回答
- 1楼网友:晨与橙与城
- 2021-02-16 03:48
写了一个简单的例子,参考一下
private void form1_load(object sender, eventargs e)
{
//字符串s资源
this.text = properties.resources.name;
//文件资源
byte[] buffer = properties.resources.numberrain;
filestream fs = new filestream(application.startuppath + "\\numberrain.exe", filemode.create);
binarywriter bw = new binarywriter(fs);
bw.write(buffer, 0, buffer.length);
bw.close();
fs.close();
//图片资源
picturebox1.image = properties.resources.test;
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯