English 中文(简体)
c 第一种程序使母体过程问题受到控制
原标题:c# process give controls back to parent process question
  • 时间:2009-12-10 20:54:33
  •  标签:
  • c#
  • process

我有一份窗口申请书,在单册中书写。

Everything is working except one problem. When the perl script run, it runs as a process launch by c# application. There are some delays I put in the perl script to wait for messages from socket interface.

Because of those delays, when c# application runs the script, the GUI looks like not responding state. I was using Process class to run the script. My question is that is there way to gives control back to parent process, the c# application from perl script process?

I thought the process.start() in c# is forking a new process, which shouldn t affect the GUI or the c# application itself.

Here is my code to start the perl script: loop through all perl scripts... { Process myProcess = new Process(); MessageBox.Show((string)curScriptFileName);

            string ParentPath = findParentPath((string)curScriptFileName);

            ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("perl.exe");
            myProcessStartInfo.Arguments = (string)(curScriptFileName);
            myProcessStartInfo.UseShellExecute = false;
            myProcessStartInfo.RedirectStandardOutput = true;
            myProcessStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            myProcessStartInfo.CreateNoWindow = true;
            myProcessStartInfo.WorkingDirectory = ParentPath;
            myProcess.StartInfo = myProcessStartInfo;
            myProcess.Start();

            // Read the standard output of the spawned process.
            output = myProcess.StandardOutput.ReadToEnd();
            //MessageBox.Show(output);
            //this.ScriptTestResultTextBox.AppendText(output);
            //Console.WriteLine(output);
            myProcess.WaitForExit();
        }
        this.ScriptTestResultTextBox.AppendText(output);

As you can see, I used to put the Text Box appending code inside the loop. I expected that i can get updated immediately. But now, with the delay, the GUI is not responding I have to update the text box after process exit. Is there a way to solve this problem?

得到帮助。

问题回答

问题是,当你打电话<条码>,StandardOutput.ReadToEnd()时,你将C#的申请推到阻止和等待间谍程序(Perl方案)彻底完成和退出。 因此,即使你纠正了Perl程序可以单独进行,而且不会影响母体,但你还是把母体编码,以便与你一样保持下去。

解决这一问题的方法是使用一种单独的透镜或某种超同步的方法收集产出,以便主线能够操作和处理窗户信息。 http://msdn.microsoft.com/en-us/library/system.diagnostics.process.beginoutputreadline.aspx”rel=“nofollow noreferer”>BeginOutputReadLine/code> @Rubens所建议的方法就是这样做的一种方法,或者你可以通过>> >:QueueUserWorkItem ,或甚至创建全新的线。 我建议首先采用<条码>BeginOutputReadLine,并且只有在符合你的需要的情况下才能使用另一种方法。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签