打印后文件没有移动,因为它被C#中的另一个进程使用? [英] File not moving after print because it being used by another process in C#?
本文介绍了打印后文件没有移动,因为它被C#中的另一个进程使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
Hello,
File not moving after print because it being used by another process in c#?
我的打印代码成功运行但我的文件移动代码没有运行其获取错误:
my print code run successfully but my file move code its not running its getting error:
it being used by another process
请帮助我。
如何解决?
Ankit Agarwal
软件工程师
我尝试过:
please help me.
how it can be resolve?
Ankit Agarwal
Software Engineer
What I have tried:
Timer myTimer=new Timer();
private void Form1_Load(object sender, EventArgs e)
{
myTimer.Tick+=new EventHandler(myTimer_Tick);
myTimer.Interval=60000;
myTimer.Start();
}
private void myTimer_Tick(object sender, EventArgs e)
{
string[] files = Directory.GetFiles(@"C:\PrintingDocument\");
foreach (string file in files)
{
//if (string.IsNullOrEmpty(file))
//{
// //txtFileName.BackColor = Color.Yellow;
// //MessageBox.Show("Please Select file.");
// return;
//}
if (File.Exists(file))
{
Process proc = new Process();
proc.StartInfo.FileName = file;
proc.StartInfo.Verb = "Print";
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.Start();
proc.WaitForExit();
//int exitcode = proc.ExitCode;
proc.Close();
MessageBox.Show("Printed Successfully" + " " + DateTime.Now.ToString());
string fileName = Path.GetFileName(file);
System.IO.File.Move(file, @"C:\PrintedDocument\" + fileName);
MessageBox.Show("Moved Successfully" + " " + DateTime.Now.ToString());
//proc.Kill();
}
else
{
MessageBox.Show("Not File found" + " " + DateTime.Now.ToString());
}
}
}
推荐答案
我解释了问题并建议你昨天需要做些什么来修复它:问题没有改变,也没有解决方案。
进程无法访问该文件,因为它正由另一个进程使用。 [ ^ ]
你在浪费更多的时间试图让一个糟糕的解决方案来解决你可能已经花费的时间 - 你会在同一时间学到一些东西......
如果您不想听我们告诉您的内容,您在提问或在我们回答问题时有什么意义吗?
I explained the problem and suggested what you need to do to fix it yesterday: the problem hasn't changed, and neither has the solution.
The process cannot access the file because it is being used by another process.[^]
You are wasting more time trying to get a bodge to work around a bad solution that you could have spent implementing this properly - and you would have learned something at the same time...
If you are not going to listen to what we tell you, is there any point in you asking a question, or in us answering it?
这篇关于打印后文件没有移动,因为它被C#中的另一个进程使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文