本文介绍了C#waitforexit问题需要尽快帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我一直四处寻找这个问题,似乎我不知所措。基本上代码在一个计时器中运行10秒,它应该在一个文件夹中查找并处理每个文件(它确实)并删除该文件。但是在我尝试修复我遇到的UI冻结问题但尝试使用线程(我是新的)之后它停止了工作。一切都很好,直到这一点,所以我不得不注释waitforexit,但如果我没有这样的功能,它将删除文件,然后通过 prs.FileName = @C:\\处理文件\\dcmtk\bin\storescu-tls.exe; 。不确定需要什么来解决这个问题。请帮忙。 我的尝试: foreach(文件中的字符串) { // if(File.Exists(s)) finalpath = Host ++ port ++ s; 流程pr = new Process(); ProcessStartInfo prs = new ProcessStartInfo(); prs.CreateNoWindow = true; prs.UseShellExecute = false; prs.RedirectStandardOutput = true; prs.WindowStyle = ProcessWindowStyle.Hidden; prs.FileName = @C:\dcmtk \ bin \ storescu-tls.exe; prs.Arguments = finalpath; textBox2.Text = s; pr.StartInfo = prs; ThreadStart ths = new ThreadStart(()=> pr.Start()); 线程th =新线程(ths); th.Start(); pr.WaitForExit(); File.Delete(s); 解决方案 I have been going round and round with this issue and seems Im at a loss. basically the code is in a timer to run ever 10 secs, it should look in a folder and process each file(and it does) and delete that file. But it stopped working after I tried to fix the UI freezing issue I had but trying to use thread(Im new). everything was fine up til this point so I had to comment out the waitforexit but if I dont have a function like this it will delete the files before it processes the files via prs.FileName = @"C:\dcmtk\bin\storescu-tls.exe";. Not sure what is needed to fix this. please help.What I have tried:foreach (string s in files) { //if (File.Exists(s)) finalpath = Host + " " + port + " " + s; Process pr = new Process(); ProcessStartInfo prs = new ProcessStartInfo(); prs.CreateNoWindow = true; prs.UseShellExecute = false; prs.RedirectStandardOutput = true; prs.WindowStyle = ProcessWindowStyle.Hidden; prs.FileName = @"C:\dcmtk\bin\storescu-tls.exe"; prs.Arguments = finalpath; textBox2.Text = s; pr.StartInfo = prs; ThreadStart ths = new ThreadStart(() => pr.Start()); Thread th = new Thread(ths); th.Start(); pr.WaitForExit(); File.Delete(s); 解决方案 这篇关于C#waitforexit问题需要尽快帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-20 07:22