|
i run a console app on top of a winform
i need to have my console app run a void
in my winform i call it by using this
saidvoid();
i need my console app to call that void the same way
|
|
|
|
|
Member 10074161 wrote: i need to have my console app run a void That still makes no sense; what is a void ? If you mean you want to call a method that exists inside a Winform then you need to use a callback method.
Use the best guess
|
|
|
|
|
what i do is when i click on a button it calls this
thisthinghere();
wich does this
private void thisthinghere()
messagebox.show("this message here");
i basicly need my console app to make what the button would make happen
|
|
|
|
|
Code in one process cannot directly call code in a completely seperate process. You have ot use some method of interprocess communication to tell the Windows Forms app to execute the method.
|
|
|
|
|
There are plenty of examples to get the stdoutput of a process by starting it programatically there by catching stdout of the started process, But i have hard time in getting the stdout of the process which is already running. (the situation is : There is one of my application triggers command window and as the application process some data will be printed in that command window) now using .net (winform) i need to catch that printed data.
Is there any possible solution to achieve this ? Your help/ideas will be appreciated !
Thank you.
-SSK.
|
|
|
|
|
You can easily capture Console output using RedirectStandardOutput [^] property.
SetOut [^] could be another option.
|
|
|
|
|
Yes, I can use Redirect Standardouput easily but there i need to declare a process and have to start it! (Means have to launch the process programatically) in my case the process is already started with some external action (could be manual).
If you want to simulate, You can take one simple console app and do some console.writeline to print some data...
Now, take one winform application from here try to capture the already opened console app printed data (console window). Hope this explains my situation.
Thanks.
|
|
|
|
|
santosh sk wrote: But i have hard time in getting the stdout of the process which is already running. (the situation is : There is one of my application triggers command window and as the application process some data will be printed in that command window) now using .net (winform) i need to catch that printed data. You state that you start the app yourself?
You could redirect[^] the output to a file; small drawback being that you'd have to wait for the command to complete before fetching that output.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I have gone thru your posted link, but that's just command line aruguments .. What im looking is c# solution.
More details about my case:
1) There is one application (C++, I dont have any control and any authorisation on this application) when we run it in debug mode (by changing some config file) it parellaly opens the command window where all debugging info gets printed.
2) Now, By using my winform app (c#), i need to catch the earlier opened command window (wiz already a running process) then capture its output.
3) Prob Im facing : Since this is already a running process i can't launch it again.. so just iam looping all running process and catching the process what i need by its process name.. there after trying to get its standard output but the error is something like *Standard output can not be redirected.*
what i understand is there is no direct way to achieve it or may be iam missing something.. (dont know even its possible to do)
|
|
|
|
|
santosh sk wrote: I have gone thru your posted link, but that's just command line aruguments .. That's the syntax. The name of the technique is called "redirecting"; one can do it with some interesting devices, like stdout and debug .
santosh sk wrote: 1) There is one application (C++, I dont have any control and any authorisation on this application) If the apps yours, you'd have at least documentation and "some" control. If it isn't, then doing this is probably not legal.
santosh sk wrote: what i understand is there is no direct way to achieve it or may be iam missing something.. (dont know even its possible to do) If it can't be redirected, then no. Are you sure it's writing to stdout?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Following code useful when trying to get the ouput of running console process:
------------------------------------------------------------------------------
Required APIs:
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("kernel32.dll")]
private static extern bool ReadConsoleOutputCharacter(IntPtr hConsoleOutput, [Out] char[] lpCharacter, uint nLength, COORD dwReadCoord, out uint lpNumberOfCharsRead);
[DllImport("kernel32.dll",
EntryPoint = "GetStdHandle",
SetLastError = true,
CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
private static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport("kernel32", SetLastError = true)]
static extern bool AttachConsole(uint dwProcessId);
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool FreeConsole();
-------------------- METHODS to get the output ---------------------
private const string strProcessName = "Process_Name";
private struct COORD
{
public short X;
public short Y;
public COORD(short X, short Y)
{
this.X = X;
this.Y = Y;
}
};
private string ReadRTConsole()
{
IntPtr rthandle = IntPtr.Zero;
char[] buffer = null;
string output = "";
int processId = 0;
Process[] processlist = Process.GetProcesses();
foreach (Process theprocess in processlist)
{
if (theprocess.ProcessName.ToLower().Equals(strProcessName))
{
processId = theprocess.Id;
break;
}
}
if (AttachConsole((uint)processId))
{
rthandle = GetStdHandle(-12);
buffer = new char[Console.BufferWidth];
StringBuilder textBuilder = new StringBuilder();
for (int i = 0; i < Console.BufferHeight; i++)
{
textBuilder.AppendLine(GetLine(buffer, rthandle, i));
}
output += textBuilder.ToString().TrimEnd();
Console.Clear();
}
FreeConsole();
return output;
}
private string GetLine(char[] buffer, IntPtr rthandle, int line)
{
uint garbage;
if (!ReadConsoleOutputCharacter(rthandle, buffer, (uint)buffer.Length, new COORD(0, (short)line), out garbage))
{
return "";
}
return new string(buffer).TrimEnd();
}
|
|
|
|
|
Cool - I assume it works?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
i have a windows application with button 'check for updates'
my problem is that when i click on 'check for updates' button, i close the program first then open it again
this.Close();
System.Diagnostics.Process.Start(mypath);
where my path is the path of the *.exe file
all that i need is
1- keep the program running without closing it
2- show loading image until getting result from the updater
3- show the program updater result
any idea about how to show loading and get updater result without closing and re-opening the application???
|
|
|
|
|
this.Close();
will defnitly close ur program
i dont think u need it part of what ur trying to do
|
|
|
|
|
John_Tadros wrote: any idea about how to show loading and get updater result without closing and re-opening the application? It's difficult to guess without knowing what your program is doing, or what it needs to do, at this point.
Use the best guess
|
|
|
|
|
Look into "click once" deployment, it solves this problem without you having to get into the details.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
There are frameworks which u can integrate to ur application. ClickOnce will be one of the option but you need you assemblies signed.
here are the free libraries which provides automatic updates
<a href="http://autoupdatemodule.codeplex.com/">http://autoupdatemodule.codeplex.com/</a>
<a href="http://autoupdater.codeplex.com">http://autoupdater.codeplex.com</a>
<a href="http://brice-lambson.blogspot.in/2011/03/automatic-update-for-codeplex-projects.html<">http://brice-lambson.blogspot.in/2011/03/automatic-update-for-codeplex-projects.html<</a>/pre>
<div class="signature">Maulik Dusara
Sr. Sofware Engineer
</div>
|
|
|
|
|
i added a registry key to regedit to auto start my app on startup
when the session open and the app start it crash on start
in the debugger it says it cant find the complete path
for a sepcific txt file it is suposed to read
when lunching the app in any other way the app works
just fine and can read said textfile easily
the text file is located in a parent folder
any idea on what could cause this
|
|
|
|
|
It sounds like you implemented this expecting the current folder of the process to always be the folder where the application is located (e.g. "C:\Program Files\MyApps\MyNewApp\NewApp.exe" with the txt file located in "C:\Program Files\MyApps"), however when you launch an application by just specifying the full path, the current folder is not changed - since this happens during startup, the current folder for your process is most likely C:\.
There are several ways to make this work, here are a couple off the top of my head:
1) Change the code to accept the file name (with full path) as a command line parameter and pass that when you are starting it up through the registry.
2) Change the code to properly locate the txt file by having that location set in the registry.
3) Change the code to check the location of the process executable file and use that to locate your parent folder.
4) Don't make any changes in the code. Instead create a Windows shortcut and in the shortcut properties specify the startup folder for your application. On system startup, invoke the shortcut instead of launching your application directly.
I am not advocating that you go with 4), but I included it to give you some options.
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
I want to connect two pc through ip address and start chat with one to another like my pc and my friend pc having no physical connect except they are connect through internet
can any one help ??? Using c# and socket programming
|
|
|
|
|
You will probably have to traverse NAT at some point, so look into how to do that.
Apart from that, it's much the same as on a LAN.
|
|
|
|
|
Can u explain it further?
|
|
|
|
|
There are plenty of chat server/client examples on the web.
Try googling chat server/client example
|
|
|
|
|
Hello,
I have a function, and i would like to let a list/array of Threads run parallel in it (inorder to protect critical sections in it).
I thought I'd create List<mutex> and assign each one to a different Thread:
for( int i =0; i<10; i++)
{ arrmutex[i] = new mutex(); }
and in the function i would like to lock with a
arrmutex.elementAt(someThread).waitOne() -> a specific variable
It tells me that i cannot do that cause my mutex list is not initialize, AND, the lock wouldn't work..
Can you please help me figure out, how to initialize a list/array of mutexes?
and how to assign each thread a mutex?
Thanks,
|
|
|
|
|
Why us a Mutex?? Are you trying to synchronize an operation between processes??
What exactly are you trying to do with this set of mutexes??
Should you be using a ManualResetEvent instead??
|
|
|
|