C# I';i’’我试图获取流程信息,但有两个错误我如何解决?

C# I';i’’我试图获取流程信息,但有两个错误我如何解决?,c#,.net,winforms,C#,.net,Winforms,行中的错误: private void ProcessInfo() { string ffMPEG = System.IO.Path.Combine(Application.StartupPath, "ffMPEG.exe"); System.Diagnostics.Process mProcess = null; System.IO.StreamReader SROutput = null;

行中的错误:

private void ProcessInfo()
        {
            string ffMPEG = System.IO.Path.Combine(Application.StartupPath, "ffMPEG.exe");
            System.Diagnostics.Process mProcess = null;

            System.IO.StreamReader SROutput = null;
            string outPut = "";

            string filepath = "D:\\source.mp4";
            string param = string.Format("-i \"{0}\"", filepath);

            System.Diagnostics.ProcessStartInfo oInfo = null;

            System.Text.RegularExpressions.Regex re = null;
            System.Text.RegularExpressions.Match m = null;
            TimeSpan Duration = 0;

            //Get ready with ProcessStartInfo
            oInfo = new System.Diagnostics.ProcessStartInfo(ffMPEG, param);
            oInfo.CreateNoWindow = true;

            //ffMPEG uses StandardError for its output.
            oInfo.RedirectStandardError = true;
            oInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;          
            oInfo.UseShellExecute = false;

            // Lets start the process

            mProcess = System.Diagnostics.Process.Start(oInfo);

            // Divert output
            SROutput = mProcess.StandardError;

            // Read all
            outPut = SROutput.ReadToEnd();

            // Please donot forget to call WaitForExit() after calling SROutput.ReadToEnd

            mProcess.WaitForExit();
            mProcess.Close();
            mProcess.Dispose();
            SROutput.Close();
            SROutput.Dispose();

            //get duration

            re = new System.Text.RegularExpressions.Regex("[D|d]uration:.((\\d|:|\\.)*)");
            m = re.Match(outPut);

            if (m.Success)
            {
                //Means the output has cantained the string "Duration"
                string temp = m.Groups(1).Value;
                string[] timepieces = temp.Split(new char[] { ':', '.' });
                if (timepieces.Length == 4)
                {

                    // Store duration
                    Duration = new TimeSpan(0, Convert.ToInt16(timepieces[0]), Convert.ToInt16(timepieces[1]), Convert.ToInt16(timepieces[2]), Convert.ToInt16(timepieces[3]));
                }
            }
        }
TimeSpan Duration = 0;
我无法将其重置为0,也无法为其分配null

错误3无法将类型“int”隐式转换为“System.TimeSpan”

行中的第二个错误:

private void ProcessInfo()
        {
            string ffMPEG = System.IO.Path.Combine(Application.StartupPath, "ffMPEG.exe");
            System.Diagnostics.Process mProcess = null;

            System.IO.StreamReader SROutput = null;
            string outPut = "";

            string filepath = "D:\\source.mp4";
            string param = string.Format("-i \"{0}\"", filepath);

            System.Diagnostics.ProcessStartInfo oInfo = null;

            System.Text.RegularExpressions.Regex re = null;
            System.Text.RegularExpressions.Match m = null;
            TimeSpan Duration = 0;

            //Get ready with ProcessStartInfo
            oInfo = new System.Diagnostics.ProcessStartInfo(ffMPEG, param);
            oInfo.CreateNoWindow = true;

            //ffMPEG uses StandardError for its output.
            oInfo.RedirectStandardError = true;
            oInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;          
            oInfo.UseShellExecute = false;

            // Lets start the process

            mProcess = System.Diagnostics.Process.Start(oInfo);

            // Divert output
            SROutput = mProcess.StandardError;

            // Read all
            outPut = SROutput.ReadToEnd();

            // Please donot forget to call WaitForExit() after calling SROutput.ReadToEnd

            mProcess.WaitForExit();
            mProcess.Close();
            mProcess.Dispose();
            SROutput.Close();
            SROutput.Dispose();

            //get duration

            re = new System.Text.RegularExpressions.Regex("[D|d]uration:.((\\d|:|\\.)*)");
            m = re.Match(outPut);

            if (m.Success)
            {
                //Means the output has cantained the string "Duration"
                string temp = m.Groups(1).Value;
                string[] timepieces = temp.Split(new char[] { ':', '.' });
                if (timepieces.Length == 4)
                {

                    // Store duration
                    Duration = new TimeSpan(0, Convert.ToInt16(timepieces[0]), Convert.ToInt16(timepieces[1]), Convert.ToInt16(timepieces[2]), Convert.ToInt16(timepieces[3]));
                }
            }
        }
TimeSpan Duration = 0;
错误4不可开票的成员 “System.Text.RegularExpressions.Match.Groups”不能像 方法


由于
0
int
,因此没有到
TimeSpan
的隐式对话。您可以使用

由于是一个属性,您需要将它与
[]
一起使用,而不是
()
类似

TimeSpan Duration = TimeSpan.Zero;

那么
TimeSpan Duration=newtimespan(0)
?@MartinZabel:)