Process Question

A

A

Hi all,

This is sort of a newbie question. I have a method that creates a process
which in turn installs MSDE. Basically, after I start the process I need to
wait until it is complete and then reboot the machine. Problem is that I am
unsure of knowing exactly when the process has completed since any code
placed after the proc.Start() method executes asynchronously. I am not
certain if what I need to do is implement some sort of callback, or if there
is some way to handle this through the process class directly. Can anyone
give me some help? Code is below:

private void doSomething()
{
Process proc = new Process();
ProcessStartInfo info = new ProcessStartInfo(selectedDrive + @"MSDE2000
ReleaseA\Setup.exe", @"INSTANCENAME=Test SECURITYMODE=SQL
SAPWD=DISABLENETWORKPROTOCOLS=0");
proc.StartInfo = info;

proc.Start();

}
 
M

Marina

I guess you could have a timer that polls the current process periodically,
to see if your process is still in the collection. Once it's no longer
there, it must have finished.
 
J

Jeffrey Tan[MSFT]

Hi Tamir,

Thanks for your feedback.

=============================================
I have tried your code, it really does not work.

To make the graphics stay permanently, you should hook in the Paint event
and use System's Graphics object to draw your graphic.

If you create and use your own Graphics object, you will draw
asynchronously on the graphics of another control, the control may refresh
its surface at any time, destroying your work in the process.

For more information, please refer to:
http://www.bobpowell.net/pictureboxhowto.htm

You should do like this:
private void button2_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
Graphics g =e.Graphics;
Pen blackPen = new Pen(Color.Red, 3);

float x = 0.0F;
float y = 0.0F;
float width = 10.0F;
float height = 10.0F;
// Draw rectangle to screen.
g.DrawRectangle(blackPen, x, y, width, height);
//g.Dispose(); You can not Dispose the system's Graphics object
}

===============================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I will work with you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi,

Thank you for posting in the community!

Based on my understanding, you use Process class to run the MSDE setup
application. Then, you want to be notified when that setup application
exited.
=============================================
There are 2 ways for your application to be notified when the process
exited: Synchronized and Asynchronous.

For Synchronized, you can follow jscottb's suggestion to use
Process.WaitForExit() method.

While for Asynchronous, you may use Process.Exited event.

Actually, event is using the callback way for your event handler to be
notified.

Note: to use Exited event, you should set Process.EnableRaisingEvents
property to true.

Sample like this:
private void button1_Click(object sender, System.EventArgs e)
{
Process proc = new Process();
ProcessStartInfo info = new ProcessStartInfo(@"\Setup.exe", @"/qb+
INSTANCENAME=NetSDK DISABLENETWORKPROTOCOLS=1 SAPWD='a'");
proc.StartInfo = info;

proc.EnableRaisingEvents=true;
proc.Exited+=new EventHandler(proc_Exited);
proc.Start();
}

private void proc_Exited(object sender, EventArgs e)
{
MessageBox.Show("exited!");
}

============================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi AZ,

Thanks for your feedback.

I am glad my reply makes sense to you, if you have any further concern,
please feel free to tell me, I will work with you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top