本文整理汇总了C#中Process.Refresh方法的典型用法代码示例。如果您正苦于以下问题:C# Process.Refresh方法的具体用法?C# Process.Refresh怎么用?C# Process.Refresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Process
的用法示例。
在下文中一共展示了Process.Refresh方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GoToJudgement
public void GoToJudgement()
{
long start = 0;
try
{
Process p = new Process();
ProcessStartInfo psI = new ProcessStartInfo(ExePath);
psI.UseShellExecute = false;
psI.RedirectStandardInput = true;
psI.RedirectStandardOutput = true;
psI.RedirectStandardError = true;
psI.CreateNoWindow = true;
p.StartInfo = psI;
p.EnableRaisingEvents = true;
p.Exited += new EventHandler(this.myProcess_Exited);
p.Start();
p.MaxWorkingSet = (IntPtr)(1024 * 1024 * 32);
sw = p.StandardInput;
sr = p.StandardOutput;
err = p.StandardError;
string input = "";
long limit = 0;
using (ProgrammingContestDataContextHandler pcdch = new ProgrammingContestDataContextHandler())
{
Problem problem = pcdch.Problems.GetById(ProBlemsID);
if (problem.Input == null || problem.Input == "")
{
FileInfo fi = new FileInfo(InputFile);
if (fi.Exists)
input = File.ReadAllText(InputFile);
else
input = "";
problem.Input = input;
pcdch.ProgrammingContestDatabase.SubmitChanges();
}
else
input = problem.Input;
limit = problem.Time * 1000;
}
sw.Write(input);
sw.Close();
int id = p.Id;
eventHandled = false;
const int SLEEP_AMOUNT = 100;
while (!p.HasExited)
{
start += SLEEP_AMOUNT;
if (start > limit)
{
break;
}
Thread.Sleep(SLEEP_AMOUNT);
p.Refresh();
}
if (start <= limit)
{
Thread.Sleep(1000);
File.WriteAllText(OutputFile, output);
using (ProgrammingContestDataContextHandler pcdch = new ProgrammingContestDataContextHandler())
{
Solution solution = pcdch.Solution.GetById(SoluTionID);
solution.Output = output;
pcdch.ProgrammingContestDatabase.SubmitChanges();
}
FileInfo fi1 = new FileInfo(OutputFile);
using (ProgrammingContestDataContextHandler pcdch = new ProgrammingContestDataContextHandler())
{
Solution solution = pcdch.Solution.GetById(SoluTionID);
if (fi1.Exists)
{
bool result = FileCompare(OutputFile, JudgeOutputFile);
if (result == true)
{
long resultId = pcdch.Result.GetByName("Accept").ID;
solution.Result = pcdch.Result.GetByName("Accept");
solution.ResultId = resultId;
}
else
{
//.........这里部分代码省略.........
示例2: Connect
public override bool Connect()
{
try
{
_isPuttyNg = IsFilePuttyNg(PuttyPath);
PuttyProcess = new Process();
PuttyProcess.StartInfo.FileName = _PuttyPath;
switch (_PuttyProtocol) {
case Putty_Protocol.raw:
PuttyProcess.StartInfo.Arguments = "-load " + "\"" + PuttyEscapeArgument(InterfaceControl.Info.PuttySession) + "\"" + " -" + _PuttyProtocol.ToString() + " -P " + InterfaceControl.Info.Port + " \"" + InterfaceControl.Info.Hostname + "\"";
break;
case Putty_Protocol.rlogin:
PuttyProcess.StartInfo.Arguments = "-load " + "\"" + PuttyEscapeArgument(InterfaceControl.Info.PuttySession) + "\"" + " -" + _PuttyProtocol.ToString() + " -P " + InterfaceControl.Info.Port + " \"" + InterfaceControl.Info.Hostname + "\"";
break;
case Putty_Protocol.ssh:
string userArgument = "";
string passwordArgument = "";
if (Settings.Default.EmptyCredentials == "windows") {
userArgument = " -l \"" + Environment.UserName + "\"";
}
else if (Settings.Default.EmptyCredentials == "custom")
{
userArgument = " -l \"" + Settings.Default.DefaultUsername + "\"";
passwordArgument = " -pw \"" + PuttyEscapeArgument(Security.Crypt.Decrypt(Settings.Default.DefaultPassword, AppInfo.General.EncryptionKey)) + "\"";
}
if (!string.IsNullOrEmpty(InterfaceControl.Info.Username)) {
userArgument = " -l \"" + InterfaceControl.Info.Username + "\"";
}
if (!string.IsNullOrEmpty(InterfaceControl.Info.Password)) {
passwordArgument = " -pw \"" + PuttyEscapeArgument(InterfaceControl.Info.Password) + "\"";
}
PuttyProcess.StartInfo.Arguments = "-load " + "\"" + PuttyEscapeArgument(InterfaceControl.Info.PuttySession)
+ "\"" + " -" + _PuttyProtocol.ToString() + " -" + (int)_PuttySSHVersion + userArgument + passwordArgument
+ " -P " + InterfaceControl.Info.Port + " \"" + InterfaceControl.Info.Hostname + "\"";
break;
case Putty_Protocol.telnet:
PuttyProcess.StartInfo.Arguments = "-load " + "\"" + PuttyEscapeArgument(InterfaceControl.Info.PuttySession) + "\"" + " -" + _PuttyProtocol.ToString() + " -P " + InterfaceControl.Info.Port + " \"" + InterfaceControl.Info.Hostname + "\"";
break;
case Putty_Protocol.serial:
PuttyProcess.StartInfo.Arguments = "-load " + "\"" + PuttyEscapeArgument(InterfaceControl.Info.PuttySession) + "\"" + " -" + _PuttyProtocol.ToString() + " -P " + InterfaceControl.Info.Port + " \"" + InterfaceControl.Info.Hostname + "\"";
break;
}
if (_isPuttyNg)
{
PuttyProcess.StartInfo.Arguments = PuttyProcess.StartInfo.Arguments + " -hwndparent " +
this.InterfaceControl.Handle.ToString();
}
//REMOVE IN RELEASE!
#if DEBUG
Runtime.MessageCollector.AddMessage(Messages.MessageClass.InformationMsg,
"PuTTY Arguments: " + PuttyProcess.StartInfo.Arguments, true);
Debug.WriteLine("PuTTY Arguments: " + PuttyProcess.StartInfo.Arguments);
#endif
PuttyProcess.EnableRaisingEvents = true;
PuttyProcess.Exited += ProcessExited;
PuttyProcess.Start();
PuttyProcess.WaitForInputIdle(Settings.Default.MaxPuttyWaitTime * 1000);
int startTicks = Environment.TickCount;
while (PuttyHandle.ToInt32() == 0 & Environment.TickCount < startTicks + (Settings.Default.MaxPuttyWaitTime * 1000))
{
if (_isPuttyNg)
{
PuttyHandle = Native.FindWindowEx(InterfaceControl.Handle, IntPtr.Zero, Constants.vbNullString, Constants.vbNullString);
}
else
{
PuttyProcess.Refresh();
PuttyHandle = PuttyProcess.MainWindowHandle;
}
if (PuttyHandle.ToInt32() == 0)
Thread.Sleep(0);
}
if (!_isPuttyNg)
{
Native.SetParent(PuttyHandle, InterfaceControl.Handle);
}
Runtime.MessageCollector.AddMessage(Messages.MessageClass.InformationMsg, Language.strPuttyStuff,
true);
Runtime.MessageCollector.AddMessage(Messages.MessageClass.InformationMsg,
string.Format(Language.strPuttyHandle, PuttyHandle.ToString()),
true);
Runtime.MessageCollector.AddMessage(Messages.MessageClass.InformationMsg,
string.Format(Language.strPuttyTitle,
PuttyProcess.MainWindowTitle), true);
Runtime.MessageCollector.AddMessage(Messages.MessageClass.InformationMsg,
string.Format(Language.strPuttyParentHandle,
this.InterfaceControl.Parent.Handle.ToString()),
//.........这里部分代码省略.........
示例3: Connect
public override bool Connect()
{
try
{
_isPuttyNg = IsFilePuttyNg(PuttyPath);
PuttyProcess = new Process();
var _with1 = PuttyProcess.StartInfo;
_with1.UseShellExecute = false;
_with1.FileName = _PuttyPath;
CommandLineArguments arguments = new CommandLineArguments();
arguments.EscapeForShell = false;
arguments.Add("-load", InterfaceControl.Info.PuttySession);
arguments.Add("-" + _PuttyProtocol.ToString());
if (_PuttyProtocol == Putty_Protocol.ssh)
{
string username = "";
string password = "";
if (!string.IsNullOrEmpty(InterfaceControl.Info.Username))
{
username = InterfaceControl.Info.Username;
}
else
{
if (Settings.Default.EmptyCredentials == "windows")
{
username = Environment.UserName;
}
else if (Settings.Default.EmptyCredentials == "custom")
{
username = Settings.Default.DefaultUsername;
}
}
if (!string.IsNullOrEmpty(InterfaceControl.Info.Password))
{
password = InterfaceControl.Info.Password;
}
else
{
if (Settings.Default.EmptyCredentials == "custom")
{
password = Security.Crypt.Decrypt(Settings.Default.DefaultPassword, AppInfo.General.EncryptionKey);
}
}
arguments.Add("-" + (int)_PuttySSHVersion);
arguments.Add("-l", username);
arguments.Add("-pw", password);
}
arguments.Add("-P", InterfaceControl.Info.Port.ToString());
arguments.Add(InterfaceControl.Info.Hostname);
if (_isPuttyNg)
{
arguments.Add("-hwndparent", InterfaceControl.Handle.ToString());
}
_with1.Arguments = arguments.ToString();
//REMOVE IN RELEASE!
#if DEBUG
Runtime.MessageCollector.AddMessage(Messages.MessageClass.InformationMsg,
"PuTTY Arguments: " + PuttyProcess.StartInfo.Arguments, true);
Debug.WriteLine("PuTTY Arguments: " + PuttyProcess.StartInfo.Arguments);
#endif
PuttyProcess.EnableRaisingEvents = true;
PuttyProcess.Exited += ProcessExited;
PuttyProcess.Start();
PuttyProcess.WaitForInputIdle(Settings.Default.MaxPuttyWaitTime * 1000);
int startTicks = Environment.TickCount;
while (PuttyHandle.ToInt32() == 0 & Environment.TickCount < startTicks + (Settings.Default.MaxPuttyWaitTime * 1000))
{
if (_isPuttyNg)
{
PuttyHandle = Native.FindWindowEx(InterfaceControl.Handle, IntPtr.Zero, Constants.vbNullString, Constants.vbNullString);
}
else
{
PuttyProcess.Refresh();
PuttyHandle = PuttyProcess.MainWindowHandle;
}
if (PuttyHandle.ToInt32() == 0)
Thread.Sleep(50);
}
if (!_isPuttyNg)
{
Native.SetParent(PuttyHandle, InterfaceControl.Handle);
}
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.strPuttyStuff, true);
//.........这里部分代码省略.........