本文整理汇总了C#中System.Diagnostics.Process.Refresh方法的典型用法代码示例。如果您正苦于以下问题:C# Process.Refresh方法的具体用法?C# Process.Refresh怎么用?C# Process.Refresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.Process
的用法示例。
在下文中一共展示了Process.Refresh方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShowLogViewer
public void ShowLogViewer()
{
Process[] process = Process.GetProcesses();
string MainFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
foreach (Process proc in process)
{
if (proc.ProcessName.Equals("LogArchive"))
// Pgm_FileName 프로그램의 실행 파일[.exe]를 제외한 파일명
{
isExecuting = true;
break;
}
else
isExecuting = false;
}
if (isExecuting)
{IntPtr procHandler = FindWindow(null, "제독업무도 바빠! 기록열람");
ShowWindow(procHandler, SW_SHOWNORMAL);
SetForegroundWindow(procHandler);
}
else if(!isExecuting)
{
if (File.Exists(Path.Combine(MainFolder, "LogArchive.exe")))
{
Process MyProcess = new Process();
MyProcess.StartInfo.FileName = "LogArchive.exe";
MyProcess.StartInfo.WorkingDirectory = MainFolder;
MyProcess.Start();
MyProcess.Refresh();
}
}
}
示例2: executeProcessWithParams
public static bool executeProcessWithParams(string stringPathToFileToExecute,string stringArguments,bool bShowCmdWindow, ref bool bCancelProcessExecution)
{
bCancelProcessExecution = false;
try
{
Process pProcess = new Process();
pProcess.StartInfo.Arguments = stringArguments;
pProcess.StartInfo.FileName = stringPathToFileToExecute;
if (bShowCmdWindow)
pProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
else
pProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
pProcess.Start();
while (! pProcess.HasExited)
{
pProcess.Refresh();
Thread.Sleep(100);
Application.DoEvents();
if (bCancelProcessExecution)
{
pProcess.Kill();
MessageBox.Show("Process execution canceled");
return false;
}
}
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
}
示例3: startbtn_Click
private void startbtn_Click(object sender, RoutedEventArgs e)
{
ProcessStartInfo psi = new ProcessStartInfo(@"C:\q\w32\q.exe");
psi.WindowStyle = ProcessWindowStyle.Normal;
_process = Process.Start(psi);
while (hWndDocked == IntPtr.Zero)
{
Thread.Sleep(100);
//_process.WaitForInputIdle(1000); //wait for the window to be ready for input;
_process.Refresh(); //update process info
if (_process.HasExited)
{
return; //abort if the process finished before we got a handle.
}
hWndDocked = _process.MainWindowHandle; //cache the window handle
}
//SetParent(_process.MainWindowHandle, helper.Handle);
SetParent(_process.MainWindowHandle, _panel.Handle);
// resize embedded application & refresh
SizeChanged += window_SizeChanged;
ResizeEmbeddedApp();
}
示例4: Main
static void Main(string[] args)
{
Process currentProcess = new Process();
currentProcess = Process.GetCurrentProcess();
CodeGenerator codeGen = new CodeGenerator();
codeGen.fileWriter();
// generating intercept.cpp and stdafx.h
InterceptCodeGenerator interceptCodeGen = new InterceptCodeGenerator();
interceptCodeGen.GenerateInterceptsFile();
/// include code here to build project i.e compiling *.cpp file created
RegistryKey localMachineHive = Registry.LocalMachine;
// Open the subkey...
RegistryKey pathLocationKey = localMachineHive.OpenSubKey( "SOFTWARE\\HolodeckEE" );
string functionXMLFile = (string)pathLocationKey.GetValue( "InstallPath" ) + "\\function_db\\functions.xml";
string holodeckFunctionDBPath = (string)pathLocationKey.GetValue( "InstallPath" ) + "\\function_db";
string Win32CodeGeneratorDumpDirPath = string.Concat(holodeckFunctionDBPath,"\\Win32CodeGeneratorDump");
if (!Directory.Exists(Win32CodeGeneratorDumpDirPath))
{
DirectoryInfo di = Directory.CreateDirectory(Win32CodeGeneratorDumpDirPath);
}
string common_h_FilePath = string.Concat(holodeckFunctionDBPath,"\\common.h");
string buildWin32InterceptFunction_cmd_FilePath = string.Concat(holodeckFunctionDBPath,"\\buildWin32InterceptFunction.cmd");
FileInfo FileToCopy = new FileInfo(common_h_FilePath);
FileToCopy.CopyTo(string.Concat(Win32CodeGeneratorDumpDirPath,"\\common.h"),true);
FileToCopy = new FileInfo(buildWin32InterceptFunction_cmd_FilePath);
FileToCopy.CopyTo(string.Concat(Win32CodeGeneratorDumpDirPath,"\\buildWin32InterceptFunction.cmd"),true);
currentProcess.Close();
currentProcess.Refresh();
Process compileProcess = new Process();
compileProcess.StartInfo.FileName = string.Concat(Win32CodeGeneratorDumpDirPath,"\\buildWin32InterceptFunction.cmd");
compileProcess.StartInfo.CreateNoWindow = true;
compileProcess.Start();
//launching AUT
Holodeck.HolodeckProcess.Start();
Holodeck.HolodeckPane.Reset();
Holodeck.HolodeckPane.File_NewProject();
Holodeck.NewProjectPane1.Reset();
Holodeck.NewProjectPane1.SetProjectLocation(@"c:\Win32InterceptGen");
Holodeck.NewProjectPane1.Next();
Holodeck.NewProjectPane2.Reset();
Holodeck.NewProjectPane2.SetApplicationName(string.Concat(Win32CodeGeneratorDumpDirPath,"\\FunctionIntercepts.exe"));
Holodeck.NewProjectPane2.Next();
Holodeck.NewProjectPane3.Reset();
Holodeck.NewProjectWizard.NativeFunctions("All");
Holodeck.NewProjectWizard.NetFunctions("All");
Holodeck.NewProjectPane3.Finish();
}
示例5: LSVorbis
public LSVorbis(LSSettings settings, LSPcmFeed pimp)
: base()
{
logger = Logger.ogg;
this.pimp = pimp;
this.settings = settings;
logger.a("creating oggenc object");
proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = Program.tools + "oggenc2.exe";
proc.StartInfo.WorkingDirectory = Program.tools.Trim('\\');
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.Arguments = string.Format(
"-Q -R 44100 {0} {1} {2} " + //.................target params
"-r -F 1 -B 16 -C 2 --raw-endianness 0 -", //...source params
(settings.ogg.compression == LSSettings.LSCompression.cbr ? "-b" : "-q"),
(settings.ogg.compression == LSSettings.LSCompression.cbr ? settings.ogg.bitrate : settings.ogg.quality),
(settings.ogg.channels == LSSettings.LSChannels.stereo ? "" : "--downmix"));
if (!File.Exists(proc.StartInfo.FileName))
{
System.Windows.Forms.MessageBox.Show(
"Could not start streaming due to a missing required file:\r\n\r\n" + proc.StartInfo.FileName +
"\r\n\r\nThis is usually because whoever made your loopstream.exe fucked up",
"Shit wont fly", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
Program.kill();
}
logger.a("starting oggenc");
proc.Start();
while (true)
{
logger.a("waiting for oggenc");
try
{
proc.Refresh();
if (proc.Modules.Count > 1) break;
logger.a("modules: " + proc.Modules.Count);
System.Threading.Thread.Sleep(10);
}
catch { }
}
/*foreach (System.Diagnostics.ProcessModule mod in proc.Modules)
{
Console.WriteLine(mod.ModuleName + " // " + mod.FileName);
}*/
logger.a("oggenc running");
pstdin = proc.StandardInput.BaseStream;
pstdout = proc.StandardOutput.BaseStream;
dump = settings.recOgg;
enc = settings.ogg;
makeShouter();
}
示例6: CloseApplication
void CloseApplication(Process process, bool force) {
int num = force ? 1 : 0x2710;
DateTime now = DateTime.Now;
TimeSpan zero = TimeSpan.Zero;
bool flag = false;
IntPtr ptr = IntPtr.Zero;
while (zero.TotalMilliseconds < num){
Trace.WriteLine(DateTime.Now + "\tCall Process.Refresh() at WinApplicationAdapter.CloseApplication");
process.Refresh();
Trace.WriteLine(DateTime.Now + "\tCall Process.Refresh() success");
Trace.WriteLine(DateTime.Now +"\tCall Process.MainWindowHandle at WinApplicationAdapter.CloseApplication");
IntPtr mainWindowHandle = IntPtr.Zero;
try{
mainWindowHandle = process.MainWindowHandle;
}
catch (InvalidOperationException){
}
if ((mainWindowHandle != ptr) && (mainWindowHandle != IntPtr.Zero)){
ptr = mainWindowHandle;
try{
process.CloseMainWindow();
}
catch (Exception exception){
Logger.Instance.AddMessage(string.Format("Process{0}.CloseMainWindow return error:\n'{1}'",process.ProcessName, exception.Message));
}
}
Trace.WriteLine(DateTime.Now + "\tCall Process.MainWindowHandle success");
try{
if (process.WaitForExit(Math.Min(0x3e8, num - ((int) zero.TotalMilliseconds)))){
flag = true;
break;
}
}
catch (Exception exception2){
Logger.Instance.AddMessage(string.Format("Process.WaitForExit return error:\n'{0}'",exception2.Message));
}
zero = DateTime.Now - now;
}
if (!flag){
if (!force){
Logger.Instance.AddMessage(string.Format("The process '{0}' was not closed in '{1}' millisecond after the Process.CloseMainWindow was invoked, trying to kill this process",process.ProcessName, num));
}
try{
process.Kill();
}
catch (Exception exception3){
Logger.Instance.AddMessage(string.Format("Process name: '{0}' is not killed.\nReason:\n'{1}'",process.ProcessName, exception3.Message));
}
if (!process.WaitForExit(0x2710)){
throw new WarningException(
string.Format("Process name: '{0}' doesn't exited in 10 seconds after the Process.Kill was invoked",process.ProcessName));
}
}
}
示例7: ClientMC
public ClientMC(Process p)
{
process = p;
process.WaitForInputIdle();
while (process.MainWindowHandle == IntPtr.Zero)
{
process.Refresh();
System.Threading.Thread.Sleep(5);
}
processHandle = WinApi.OpenProcess(WinApi.PROCESS_ALL_ACCESS, 0, (uint)process.Id);
}
示例8: LSLame
public LSLame(LSSettings settings, LSPcmFeed pimp)
{
logger = Logger.mp3;
this.pimp = pimp;
this.settings = settings;
logger.a("creating lame object");
proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = Program.tools + "lame.exe";
proc.StartInfo.WorkingDirectory = Program.tools.Trim('\\');
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.Arguments = string.Format(
"{0} {1} -h -m {2} --noreplaygain -S " + //..................target params
"-r -s {3} --bitwidth 16 --signed --little-endian - -", //...source params
(settings.mp3.compression == LSSettings.LSCompression.cbr ? "--preset cbr" : "-V"),
(settings.mp3.compression == LSSettings.LSCompression.cbr ? settings.mp3.bitrate : settings.mp3.quality),
(settings.mp3.channels == LSSettings.LSChannels.stereo ? "j" : "s -a"),
settings.samplerate);
if (!File.Exists(proc.StartInfo.FileName))
{
System.Windows.Forms.MessageBox.Show(
"Could not start streaming due to a missing required file:\r\n\r\n" + proc.StartInfo.FileName +
"\r\n\r\nThis is usually because whoever made your loopstream.exe fucked up",
"Shit wont fly", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
Program.kill();
}
logger.a("starting lame");
proc.Start();
while (true)
{
logger.a("waiting for lame");
try
{
proc.Refresh();
if (proc.Modules.Count > 1) break;
logger.a("modules: " + proc.Modules.Count);
System.Threading.Thread.Sleep(10);
}
catch { }
}
logger.a("lame running");
pstdin = proc.StandardInput.BaseStream;
pstdout = proc.StandardOutput.BaseStream;
dump = settings.recMp3;
enc = settings.mp3;
makeShouter();
}
示例9: FindMainWindowHandleOfProcess
/// <summary>
/// Finds the main window of the given process and returns its window handle.
/// </summary>
/// <param name="processname"></param>
/// <exception cref="System.Exception"></exception>
/// <returns></returns>
public IntPtr FindMainWindowHandleOfProcess(Process p)
{
p.Refresh();
if (p.HasExited)
throw new ArgumentException("The process has exited.");
IntPtr hWnd = p.MainWindowHandle;
if (hWnd == IntPtr.Zero)
throw new ArgumentException("Could not find Main Window.");
return hWnd;
}
示例10: WaitForFinish
static void WaitForFinish(string callDescription, Process proc)
{
if (proc.WaitForExit((int)TimeSpan.FromSeconds(20).TotalMilliseconds)) return;
proc.Refresh();
LogOutput.Log.Warning("Call taking a long time, will abort in 2 minutes: " + callDescription);
if (!proc.WaitForExit((int)TimeSpan.FromMinutes(2).TotalMilliseconds))
{
LogOutput.Log.Error("ABORTING LONG CALL: " + callDescription);
// ReSharper disable EmptyGeneralCatchClause
try
{
proc.Kill();
proc.Refresh();
}
catch
{
}
// ReSharper restore EmptyGeneralCatchClause
}
}
示例11: SetWindowPosition
public static void SetWindowPosition(Process process, int x, int y, int width, int height)
{
IntPtr p = IntPtr.Zero;
while (p == IntPtr.Zero)
{
// process.WaitForInputIdle(100); //wait for the window to be ready for input;
process.Refresh(); //update process info
if (process.HasExited)
{
return; //abort if the process finished before we got a handle.
}
p = process.MainWindowHandle; //cache the window handle
}
SetWindowPos(p, 0, x, y, width, height, SWP_SHOWWINDOW);
}
示例12: RunMongo
private static void RunMongo(string script)
{
var psi = new ProcessStartInfo("mongo", string.Format("--norc --eval \"{0}\" test", script))
{
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};
var process = new Process
{
StartInfo = psi,
EnableRaisingEvents = true
};
var stdOut = new StringBuilder();
var stdErr = new StringBuilder();
Action<StringBuilder, string> handleLine = (builder, line) =>
{
if (line == null)
return;
builder.AppendLine(line);
};
process.OutputDataReceived += (obj, e) => handleLine(stdOut, e.Data);
process.ErrorDataReceived += (obj, e) => handleLine(stdErr, e.Data);
process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
do
{
process.WaitForExit(100);
process.Refresh();
} while (!process.HasExited);
process.WaitForExit();
var infoOutput = stdOut.ToString();
var errorOutput = stdErr.ToString();
var exitCode = process.ExitCode;
if (exitCode > 0)
{
throw new Exception(string.Format("Mongo exited with code {0}", exitCode));
}
}
示例13: button_Click
private void button_Click(object sender, RoutedEventArgs e)
{
p = System.Diagnostics.Process.Start(ofd.FileName);
//念のため待つ。
p.WaitForInputIdle();
//ウィンドウハンドルが取得できるか、
//生成したプロセスが終了するまで待ってみる。
while (p.MainWindowHandle == IntPtr.Zero &&
p.HasExited == false)
{
System.Threading.Thread.Sleep(1);
p.Refresh();
}
}
示例14: GetMainWindowHandle
private int GetMainWindowHandle(Process proc)
{
proc.Refresh();
var timestamp = DateTime.Now;
while (true)
{
if (proc.MainWindowHandle != IntPtr.Zero)
return proc.MainWindowHandle.ToInt32();
if (DateTime.Now.Subtract(timestamp).TotalSeconds > 60)
{
throw new TimeoutException("Can't find main window");
}
Thread.Sleep(250);
}
}
示例15: scanJava
public static bool scanJava(Process p)
{
p.Refresh();
try
{
if (p.HasExited)
{
return false;
}
}
catch (Exception)
{
return false;
}
//Console.WriteLine("Scanning " + p.ProcessName);
IntPtr Addy = new IntPtr();
List<MEMORY_BASIC_INFORMATION> MemReg = new List<MEMORY_BASIC_INFORMATION>();
while (true)
{
MEMORY_BASIC_INFORMATION MemInfo = new MEMORY_BASIC_INFORMATION();
int MemDump = VirtualQueryEx(p.Handle, Addy, out MemInfo, Marshal.SizeOf(MemInfo));
if (MemDump == 0) break;
if (0 != (MemInfo.State & MEM_COMMIT) && 0 != (MemInfo.Protect & WRITABLE) && 0 == (MemInfo.Protect & PAGE_GUARD))
{
MemReg.Add(MemInfo);
}
Addy = new IntPtr(MemInfo.BaseAddress.ToInt64() + MemInfo.RegionSize.ToInt64());
}
for (int i = 0; i < MemReg.Count; i++)
{
byte[] buff = new byte[MemReg[i].RegionSize.ToInt32()];
ReadProcessMemory(p.Handle, MemReg[i].BaseAddress, buff, MemReg[i].RegionSize.ToInt32(), IntPtr.Zero);
long Result = IndexOf(buff, javameter);
if (Result > 0)
{
buff = null;
GC.Collect();
return true;
}
buff = null;
}
GC.Collect();
return false;
}