![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Mar 2006
Posts: 40
Rep Power: 0
![]() |
Executing a remote program from a thread within a service
I have a C# client/server program that functions as expected. In attempts to get rid of the console window being displayed, I tried nesting the server code into a service with threads and such.
The problem occurs when the client tries to send across an "execute transaction", which executes a client specified program on the server. The remote process terminates but somehow doesn't let my program know, so the process hangs until I kill it. I'm exectuing the remote program by using the Process method: Process myProcess;
myProcess = new Process();
myProcess = Process.Start("c:\\cycle.exe");
myProcess.WaitForExit(35000);
int errCk = myProcess.ExitCode;
myProcess.Close();No matter how many milliseconds I use, the thread never receives the notice of termination of the remote process so the client hangs. Is there any way I can kill the process after a specified interval and notify the thread that it died? I am also open to eliminating the console window another way, outside of services and threads... if anyone has any suggestions. |
|
|
|
|
|
#2 | |
|
Programming Guru
![]() ![]() ![]() |
Quote:
Try this: ... using System.Runtime.InteropServices; ... -------------------------------- And at the top of your class, put this: [DllImport("user32.dll")]
publicstaticextern IntPtr FindWindow(string lpClassName,string lpWindowName);
[DllImport("user32.dll")]
staticexternbool ShowWindow(IntPtr hWnd, int nCmdShow);-------------------------------- And within the Main function put this: IntPtr hWnd = FindWindow(null, System.Windows.Forms.Application.ExecutablePath ); //put your console window caption here
if(hWnd != IntPtr.Zero)
{
//Hide the window
ShowWindow(hWnd, 0); // 0 = SW_HIDE
}-------------------------------- If you wanted it to show again, you could do this: if(hWnd != IntPtr.Zero)
{
//Show window again
ShowWindow(hWnd, 1); //1 = SW_SHOWNORMA
}
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
|
#3 |
|
Programmer
Join Date: Mar 2006
Posts: 40
Rep Power: 0
![]() |
Thank you so much IR!!! This is exactly what I needed.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Language display in program | Prm753 | C++ | 3 | May 30th, 2006 5:45 PM |
| Creating a program to test a program | sixstringartist | C | 8 | Jan 21st, 2006 1:15 PM |
| Loading a program into memory and executing it... | Datalisk | Assembly | 8 | Oct 24th, 2005 5:56 AM |
| CPU Usage goes to 100% when pthread_cond_wait is being used | zen_buddha | C++ | 1 | Oct 13th, 2005 5:59 AM |
| Using ODBC to connect to a remote database in a C program | bigi | C++ | 1 | Mar 8th, 2005 3:19 PM |