gpt4 book ai didi

c# - 收到错误 'The process cannot access the file because it is being used by another process.'

转载 作者:太空宇宙 更新时间:2023-11-03 16:32:33 26 4
gpt4 key购买 nike

我收到一个错误:

The process cannot access the file 'E:\testing\check1.txt' because it is being used by another process.

这是我的代码:

private void timer2_Tick(object sender, EventArgs e)
{
StreamWriter sw1 = new StreamWriter("E:\\testing\\check1.txt");
sw1.Flush();
if (dt[playback_iterator].iden == this.event_id)
{

foreach (Type type in asm1.GetTypes())
{
if (type.IsSubclassOf(typeof(System.Windows.Forms.Form)))
{
System.Windows.Forms.Form f = (System.Windows.Forms.Form)Activator.CreateInstance(type);
foreach (Control ctrl in f.Controls)
{
if (ctrl.Handle.ToInt32() == dt[playback_iterator].hndl)
{
if (ctrl.BackColor.R == this.r_comp && ctrl.BackColor.G == this.g_comp && ctrl.BackColor.G == this.g_comp)
{
sw1.WriteLine("verification point was set and the test passed");
/*success ob = new success();
ob.Show();*/
}
else
{
sw1.WriteLine("verification point test failed");
}

}
}

}
sw1.Close();

if (dt[playback_iterator].hndl == -1 && dt[playback_iterator].x == -1 && dt[playback_iterator].y == -1)
{
timer2.Enabled = false;
}
MoveMouse(dt[playback_iterator].hndl, dt[playback_iterator].x, dt[playback_iterator].y);
if (dt[playback_iterator].click_detect.Equals("yes"))
{
ClickMouse(MonkeyButtons.btcLeft, dt[playback_iterator].x, dt[playback_iterator].y, 0, 0);
}
if (dt[playback_iterator].word != "")
{
++count;
StringBuilder wd = new StringBuilder(dt[playback_iterator].word);
SetForegroundWindow(dt[playback_iterator].hndl);
SendKeys.Send(dt[playback_iterator].word);
}
playback_iterator++;

}
}
}

最佳答案

您可以使用 using block 并写入文本文件

using (StreamWriter sw1 = new StreamWriter("E:\\testing\\check1.txt"))
{
if (condition)
{
foreach (Type type in asm1.GetTypes())
{
if (contition)
{
sw1.WriteLine("verification point was set and the test passed");
}
}
}

关于c# - 收到错误 'The process cannot access the file because it is being used by another process.',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10408842/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com