本文整理汇总了C#中ProcessInfo类的典型用法代码示例。如果您正苦于以下问题:C# ProcessInfo类的具体用法?C# ProcessInfo怎么用?C# ProcessInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProcessInfo类属于命名空间,在下文中一共展示了ProcessInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessInfo_TestEqualishWorksAlwaysReturnsFalseForDifferentProcesses
public void ProcessInfo_TestEqualishWorksAlwaysReturnsFalseForDifferentProcesses()
{
var info1 = new ProcessInfo("process.exe", "TestDocument.doc *");
var info2 = new ProcessInfo("process2.exe", "TestDocument.doc");
info1.IsEqualishTo(info2).Should().BeFalse("because they're different processes");
}
示例2: ProcessInfo_TestEverything
public void ProcessInfo_TestEverything()
{
ProcessInfo p1 = new ProcessInfo();
Assert.AreEqual(0, p1.ProcessId);
Assert.AreEqual(ProcessInfo.ProcessType.Unknown, p1.Type);
Assert.IsNull(p1.EndPoint);
Assert.IsNull(p1.Label);
Assert.AreEqual(ProcessInfo.StatusCode.Unknown, p1.Status);
Assert.IsNull(p1.AliveTimestamp);
PublicEndPoint ep1 = new PublicEndPoint() { Host = "swcwin.serv.usu.edu", Port = 32541 };
DateTime t1 = DateTime.Now;
ProcessInfo p2 = new ProcessInfo()
{
ProcessId = 10,
Type = ProcessInfo.ProcessType.Player,
EndPoint = ep1,
Label = "Test Process",
Status = ProcessInfo.StatusCode.Initializing,
AliveTimestamp = t1
};
Assert.AreEqual(10, p2.ProcessId);
Assert.AreEqual(ProcessInfo.ProcessType.Player, p2.Type);
Assert.AreEqual(ep1, p2.EndPoint);
Assert.AreEqual("Test Process", p2.Label);
Assert.AreEqual(ProcessInfo.StatusCode.Initializing, p2.Status);
Assert.AreEqual("Initializing", p2.StatusString);
Assert.AreEqual(t1, p2.AliveTimestamp);
}
示例3: ProcessMonitor
public ProcessMonitor(Process p)
{
m_process = p;
m_info = new ProcessInfo(p);
UpdateDeltas();
//m_cpucounter = new PerformanceCounter("Processor", "% Processor Time", GetPerformanceCounterProcessName(m_process.Id), true);
}
示例4: StreamEncodingCanBeChanged
public void StreamEncodingCanBeChanged()
{
var info = new ProcessInfo("somewhere");
var encoding = Encoding.UTF32;
info.StreamEncoding = encoding;
Assert.AreEqual(encoding, info.StreamEncoding);
}
示例5: StandardInputContentCanBeChanged
public void StandardInputContentCanBeChanged()
{
var info = new ProcessInfo("somewhere");
var expected = "some data to pass in";
info.StandardInputContent = expected;
Assert.AreEqual(expected, info.StandardInputContent);
}
示例6: Show
public void Show(ProcessInfo process, string whatsHigh)
{
this._Process = process;
this.Text = "Warning! Process taking high " + whatsHigh;
this.TitleLabel.Text = "The following process is taking high " + whatsHigh + " and should be closed:";
this.ProcessNameLabel.Text = process.Title;
this.PostponeButton.Text = string.Format("Postpone {0} mins", Settings.Default.Default_Postpone_Time.TotalMinutes);
this.CPULabel.Text = process.CpuUsage + "%";
this.MemoryLabel.Text = (process.WorkingSet / 1048576) + " MB";
try
{
Process realProcess = Process.GetProcessById(process.Id);
this.ProcessNameLabel.Text = realProcess.MainWindowTitle;
}
catch
{
}
this.Show();
this.Refresh();
this.TopMost = true;
this.DummyTextBox.Focus();
}
示例7: MinimalConstructorSetsFilename
public void MinimalConstructorSetsFilename()
{
var filename = "nameoffile";
var info = new ProcessInfo(filename);
Assert.AreEqual(filename, info.FileName);
Assert.AreEqual(2, info.TimeOut.Minutes);
}
示例8: CreateProcess
public static System.Diagnostics.Process CreateProcess(string path, string args, string currentDirectory)
{
if (!File.Exists(path))
{
throw new ArgumentException("File does not exist");
}
ProcessInfo proc = new ProcessInfo();
try
{
var inf = new StartupInfo();
inf.cb = (uint)Marshal.SizeOf(typeof(StartupInfo));
var cmd = path;
if(!string.IsNullOrWhiteSpace(args))
{
cmd += " " + args;
}
if (!CreateProcess(null, cmd, IntPtr.Zero, IntPtr.Zero, false, CREATE_BREAKAWAY_FROM_JOB | CREATE_NO_WINDOW, IntPtr.Zero, currentDirectory, ref inf, out proc))
{
throw new InvalidOperationException("Couldn't create process");
}
return System.Diagnostics.Process.GetProcessById(proc.ProcessId);
}
finally
{
if (proc.hProcess != IntPtr.Zero)
{
Interop.CloseHandle(proc.hProcess);
}
}
}
示例9: ShouldNotUseATimeoutIfTimeoutSetToInfiniteOnProcessInfo
public void ShouldNotUseATimeoutIfTimeoutSetToInfiniteOnProcessInfo()
{
ProcessInfo processInfo = new ProcessInfo("cmd.exe", "/C @echo Hello World");
processInfo.TimeOut = ProcessInfo.InfiniteTimeout;
ProcessResult result = executor.Execute(processInfo);
AssertProcessExitsSuccessfully(result);
Assert.AreEqual("Hello World", result.StandardOutput.Trim());
}
示例10: ProcessInfo_TestEqualishWorksWithUnsavedDocumentMarkers
public void ProcessInfo_TestEqualishWorksWithUnsavedDocumentMarkers()
{
var processName = "process.exe";
var info1 = new ProcessInfo(processName, "TestDocument.doc *");
var info2 = new ProcessInfo(processName, "TestDocument.doc");
info1.IsEqualishTo(info2).Should().BeTrue("because the process name is the same and the window title is basically the same!");
}
示例11: IfStandardInputContentIsSetThenStandardInputIsRedirected
public void IfStandardInputContentIsSetThenStandardInputIsRedirected()
{
ProcessInfo info = new ProcessInfo("temp");
info.StandardInputContent = "Some content";
Process process = info.CreateProcess();
Assert.IsTrue(process.StartInfo.RedirectStandardInput);
Assert.IsTrue(!process.StartInfo.UseShellExecute);
}
示例12: SetEnvironmentVariables
public void SetEnvironmentVariables()
{
ProcessInfo processInfo = new ProcessInfo("cmd.exe", "/C set foo", null);
processInfo.EnvironmentVariables["foo"] = "bar";
ProcessResult result = executor.Execute(processInfo);
AssertProcessExitsSuccessfully(result);
Assert.AreEqual("foo=bar\r\n", result.StandardOutput);
}
示例13: WriteToStandardInput
private static void WriteToStandardInput(Process process, ProcessInfo processInfo)
{
if (process.StartInfo.RedirectStandardInput)
{
process.StandardInput.Write(processInfo.StandardInputContent);
process.StandardInput.Flush();
process.StandardInput.Close();
}
}
示例14: ProcessInfo_ConstructorShouldSetProperties
public void ProcessInfo_ConstructorShouldSetProperties()
{
var name = "process.exe";
var title = "window title";
var info = new ProcessInfo(name, title);
info.Name.Should().BeEquivalentTo(name);
info.WindowTitle.Should().BeEquivalentTo(title);
}
示例15: ForceProcessTimeoutBecauseTargetIsNonTerminating
public void ForceProcessTimeoutBecauseTargetIsNonTerminating()
{
ProcessInfo processInfo = new ProcessInfo("sleeper.exe");
processInfo.TimeOut = 100;
ProcessResult result = executor.Execute(processInfo);
Assert.IsTrue(result.TimedOut, "process did not time out, but it should have.");
Assert.IsNotNull(result.StandardOutput, "some output should have been produced");
AssertProcessExitsWithFailure(result);
}