Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 12th, 2007, 5:34 PM   #1
Druid
Programmer
 
Join Date: Mar 2006
Posts: 40
Rep Power: 0 Druid is on a distinguished road
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.
Druid is offline   Reply With Quote
Old Apr 12th, 2007, 6:04 PM   #2
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,473
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Quote:
Originally Posted by Druid View Post
I am also open to eliminating the console window another way, outside of services and threads... if anyone has any suggestions.
That is a lot of effort if your only intention was to hide the console window from the user's view.

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."
Infinite Recursion is offline   Reply With Quote
Old Apr 12th, 2007, 10:25 PM   #3
Druid
Programmer
 
Join Date: Mar 2006
Posts: 40
Rep Power: 0 Druid is on a distinguished road
Thank you so much IR!!! This is exactly what I needed.
Druid is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Language display in program Prm753 C++ 3 May 30th, 2006 6:45 PM
Creating a program to test a program sixstringartist C 8 Jan 21st, 2006 2:15 PM
Loading a program into memory and executing it... Datalisk Assembly 8 Oct 24th, 2005 6:56 AM
CPU Usage goes to 100% when pthread_cond_wait is being used zen_buddha C++ 1 Oct 13th, 2005 6:59 AM
Using ODBC to connect to a remote database in a C program bigi C++ 1 Mar 8th, 2005 4:19 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:16 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC