I am writing a program that will automate a series of application
installations. I want to give the user the option of stopping the
program's execution in between installations (for example, give the
user the chance to stop the program after the second installation
before it continues on to the third installation). However, I want the
user to be able to start the installations and walk away as well, so I
can't ask the user if he wants to continue if that means execution will
stop and wait for his response. I thought of two ways to do this,
though there may be a better way I'm not thinking of.
First, I could have a button on my program's Form that says "Stop
Installation." I tried doing this, and having that button's click
event simply set a flag that says to stop execution after the current
installation. However, when an installation starts, I get an hour
glass and I am unable to hit the button that I created. If this is
going to work, I need to find a way to continue allowing the user to
enter input even while the program is running an installation (with the
Process class).
Second, I could pop up a dialog asking the user if he wants to
continue, which closes after X number of seconds without a response. I
think this would work, but I'm new to C# and I haven't found a
relativly easy way of doing this.
Does anyone have an idea of how I could accomplish this? Thank you in
advance! 4 2038
Hi,
The first idea sounds much better IMO (stop button). I don't think your
problem has to do with the Process class at all. It probably has to do with
the fact that you're blocking the UI thread. Perhaps you're calling
Process.WaitFor Exit()? The following code should work fine:
// 2.0 Framework code
Process process = new Process();
process.StartIn fo.FileName = @"C:\Install.ms i";
// anonymous method
process.Exited += delegate(object senderP, EventArgs eP)
{
// this code is executed when the process terminates
int returnValue = process.ExitCod e;
};
process.EnableR aisingEvents = true;
process.Start() ;
// let the thread return to the caller so that the UI is responsive
If you're using the 1.* Framework then you can register an event handler
with Exited to do the same thing as a above but without the anonymous part.
--
Dave Sexton
"bjm" <cy**********@h otmail.comwrote in message
news:11******** *************@1 6g2000cwy.googl egroups.com...
>I am writing a program that will automate a series of application
installations. I want to give the user the option of stopping the
program's execution in between installations (for example, give the
user the chance to stop the program after the second installation
before it continues on to the third installation). However, I want the
user to be able to start the installations and walk away as well, so I
can't ask the user if he wants to continue if that means execution will
stop and wait for his response. I thought of two ways to do this,
though there may be a better way I'm not thinking of.
First, I could have a button on my program's Form that says "Stop
Installation." I tried doing this, and having that button's click
event simply set a flag that says to stop execution after the current
installation. However, when an installation starts, I get an hour
glass and I am unable to hit the button that I created. If this is
going to work, I need to find a way to continue allowing the user to
enter input even while the program is running an installation (with the
Process class).
Second, I could pop up a dialog asking the user if he wants to
continue, which closes after X number of seconds without a response. I
think this would work, but I'm new to C# and I haven't found a
relativly easy way of doing this.
Does anyone have an idea of how I could accomplish this? Thank you in
advance!
You're completly right, the Process.WaitFor Exit was blocking the
thread. I like this idea of using the Process's Exited event.
However, I need to wait until the current installation is finished
before starting the next one, so I need another way of accomplishing
the same effect as WaitForExit while not blocking the UI thread so I
still allow user input. I tried setting a flag in the exited event
handler (I am using 1.1 Framework) and then placing a while(flag is not
set) in the UI code, but after a few seconds of this while loop, the
program goes unresponsive and doesn't come back up, even after the
installation completes. How can I wait for the current process to exit
while not blocking the UI thread so that I can still recieve user
input? Thank you very much for your help!
Dave Sexton wrote:
Hi,
The first idea sounds much better IMO (stop button). I don't think your
problem has to do with the Process class at all. It probably has to do with
the fact that you're blocking the UI thread. Perhaps you're calling
Process.WaitFor Exit()? The following code should work fine:
// 2.0 Framework code
Process process = new Process();
process.StartIn fo.FileName = @"C:\Install.ms i";
// anonymous method
process.Exited += delegate(object senderP, EventArgs eP)
{
// this code is executed when the process terminates
int returnValue = process.ExitCod e;
};
process.EnableR aisingEvents = true;
process.Start() ;
// let the thread return to the caller so that the UI is responsive
If you're using the 1.* Framework then you can register an event handler
with Exited to do the same thing as a above but without the anonymous part.
--
Dave Sexton
"bjm" <cy**********@h otmail.comwrote in message
news:11******** *************@1 6g2000cwy.googl egroups.com...
I am writing a program that will automate a series of application
installations. I want to give the user the option of stopping the
program's execution in between installations (for example, give the
user the chance to stop the program after the second installation
before it continues on to the third installation). However, I want the
user to be able to start the installations and walk away as well, so I
can't ask the user if he wants to continue if that means execution will
stop and wait for his response. I thought of two ways to do this,
though there may be a better way I'm not thinking of.
First, I could have a button on my program's Form that says "Stop
Installation." I tried doing this, and having that button's click
event simply set a flag that says to stop execution after the current
installation. However, when an installation starts, I get an hour
glass and I am unable to hit the button that I created. If this is
going to work, I need to find a way to continue allowing the user to
enter input even while the program is running an installation (with the
Process class).
Second, I could pop up a dialog asking the user if he wants to
continue, which closes after X number of seconds without a response. I
think this would work, but I'm new to C# and I haven't found a
relativly easy way of doing this.
Does anyone have an idea of how I could accomplish this? Thank you in
advance!
Hi,
You don't want a while loop in the method that starts the process. What you
need is for that method to return to the caller A.S.A.P.
You can use a Queue to hold the list of processes that must be started in
the order that they must be executed:
private readonly System.Collecti ons.Queue processQueue =
new System.Collecti ons.Queue();
private bool cancelled;
When your program starts, create all of the process objects that it needs
and enqueue them in the correct order (first-in-first-out):
void InitializeProce sses()
{
processQueue.En queue(CreatePro cess("calc"));
processQueue.En queue(CreatePro cess("msconfig" ));
processQueue.En queue(CreatePro cess("msinfo32" ));
}
Process CreateProcess(s tring fileName)
{
Process process = new Process();
process.StartIn fo.FileName = fileName;
process.EnableR aisingEvents = true;
process.Exited += Process_Exited; // 2.0 delegate inference syntax
return process;
}
Add an event handler for the Exited event and use the following method:
void Process_Exited( object sender, EventArgs e)
{
RunNextProcess( );
}
Then create a method that will dequeue the next process and start it:
void RunNextProcess( )
{
if (cancelled || processQueue.Co unt == 0)
// The entire process may be cancelled and
// since the last process has an event handler for Exited
// this method will be invoked even though there are
// no more processes to be executed, so we check
// the Count and exit when it's zero
return;
Process process = (Process) processQueue.De queue();
process.Start() ;
}
When you want to begin the first process simply call RunNextProcess( ) and
return to the caller. As long as you never call RunNextProcess from a
background thread you don't have to worry about thread-safety here since the
processes will be started serially by the Exited event.
To cancel the process set the cancelled field to true. If you want you can
store the currently running process in a field so that you can call
CloseMainWindow on it as well. I haven't added code to allow you to reset
the entire operation, though, so you'll want to encapsulate this code in an
object if that behavior is required.
--
Dave Sexton
"bjm" <bj*******@gmai l.comwrote in message
news:11******** *************@t 46g2000cwa.goog legroups.com...
You're completly right, the Process.WaitFor Exit was blocking the
thread. I like this idea of using the Process's Exited event.
However, I need to wait until the current installation is finished
before starting the next one, so I need another way of accomplishing
the same effect as WaitForExit while not blocking the UI thread so I
still allow user input. I tried setting a flag in the exited event
handler (I am using 1.1 Framework) and then placing a while(flag is not
set) in the UI code, but after a few seconds of this while loop, the
program goes unresponsive and doesn't come back up, even after the
installation completes. How can I wait for the current process to exit
while not blocking the UI thread so that I can still recieve user
input? Thank you very much for your help!
Dave Sexton wrote:
>Hi,
The first idea sounds much better IMO (stop button). I don't think your problem has to do with the Process class at all. It probably has to do with the fact that you're blocking the UI thread. Perhaps you're calling Process.WaitFo rExit()? The following code should work fine:
// 2.0 Framework code
Process process = new Process(); process.StartI nfo.FileName = @"C:\Install.ms i";
// anonymous method process.Exit ed += delegate(object senderP, EventArgs eP) { // this code is executed when the process terminates
int returnValue = process.ExitCod e; };
process.Enable RaisingEvents = true; process.Start( );
// let the thread return to the caller so that the UI is responsive
If you're using the 1.* Framework then you can register an event handler with Exited to do the same thing as a above but without the anonymous part.
-- Dave Sexton
"bjm" <cy**********@h otmail.comwrote in message news:11******* **************@ 16g2000cwy.goog legroups.com...
>I am writing a program that will automate a series of application
installations. I want to give the user the option of stopping the
program's execution in between installations (for example, give the
user the chance to stop the program after the second installation
before it continues on to the third installation). However, I want the
user to be able to start the installations and walk away as well, so I
can't ask the user if he wants to continue if that means execution will
stop and wait for his response. I thought of two ways to do this,
though there may be a better way I'm not thinking of.
First, I could have a button on my program's Form that says "Stop
Installation." I tried doing this, and having that button's click
event simply set a flag that says to stop execution after the current
installation. However, when an installation starts, I get an hour
glass and I am unable to hit the button that I created. If this is
going to work, I need to find a way to continue allowing the user to
enter input even while the program is running an installation (with the
Process class).
Second, I could pop up a dialog asking the user if he wants to
continue, which closes after X number of seconds without a response. I
think this would work, but I'm new to C# and I haven't found a
relativly easy way of doing this.
Does anyone have an idea of how I could accomplish this? Thank you in
advance!
That should work great. Thank you very much!!
Dave Sexton wrote:
Hi,
You don't want a while loop in the method that starts the process. What you
need is for that method to return to the caller A.S.A.P.
You can use a Queue to hold the list of processes that must be started in
the order that they must be executed:
private readonly System.Collecti ons.Queue processQueue =
new System.Collecti ons.Queue();
private bool cancelled;
When your program starts, create all of the process objects that it needs
and enqueue them in the correct order (first-in-first-out):
void InitializeProce sses()
{
processQueue.En queue(CreatePro cess("calc"));
processQueue.En queue(CreatePro cess("msconfig" ));
processQueue.En queue(CreatePro cess("msinfo32" ));
}
Process CreateProcess(s tring fileName)
{
Process process = new Process();
process.StartIn fo.FileName = fileName;
process.EnableR aisingEvents = true;
process.Exited += Process_Exited; // 2.0 delegate inference syntax
return process;
}
Add an event handler for the Exited event and use the following method:
void Process_Exited( object sender, EventArgs e)
{
RunNextProcess( );
}
Then create a method that will dequeue the next process and start it:
void RunNextProcess( )
{
if (cancelled || processQueue.Co unt == 0)
// The entire process may be cancelled and
// since the last process has an event handler for Exited
// this method will be invoked even though there are
// no more processes to be executed, so we check
// the Count and exit when it's zero
return;
Process process = (Process) processQueue.De queue();
process.Start() ;
}
When you want to begin the first process simply call RunNextProcess( ) and
return to the caller. As long as you never call RunNextProcess from a
background thread you don't have to worry about thread-safety here since the
processes will be started serially by the Exited event.
To cancel the process set the cancelled field to true. If you want you can
store the currently running process in a field so that you can call
CloseMainWindow on it as well. I haven't added code to allow you to reset
the entire operation, though, so you'll want to encapsulate this code in an
object if that behavior is required.
--
Dave Sexton
"bjm" <bj*******@gmai l.comwrote in message
news:11******** *************@t 46g2000cwa.goog legroups.com...
You're completly right, the Process.WaitFor Exit was blocking the
thread. I like this idea of using the Process's Exited event.
However, I need to wait until the current installation is finished
before starting the next one, so I need another way of accomplishing
the same effect as WaitForExit while not blocking the UI thread so I
still allow user input. I tried setting a flag in the exited event
handler (I am using 1.1 Framework) and then placing a while(flag is not
set) in the UI code, but after a few seconds of this while loop, the
program goes unresponsive and doesn't come back up, even after the
installation completes. How can I wait for the current process to exit
while not blocking the UI thread so that I can still recieve user
input? Thank you very much for your help!
Dave Sexton wrote:
Hi,
The first idea sounds much better IMO (stop button). I don't think your
problem has to do with the Process class at all. It probably has to do
with
the fact that you're blocking the UI thread. Perhaps you're calling
Process.WaitFor Exit()? The following code should work fine:
// 2.0 Framework code
Process process = new Process();
process.StartIn fo.FileName = @"C:\Install.ms i";
// anonymous method
process.Exited += delegate(object senderP, EventArgs eP)
{
// this code is executed when the process terminates
int returnValue = process.ExitCod e;
};
process.EnableR aisingEvents = true;
process.Start() ;
// let the thread return to the caller so that the UI is responsive
If you're using the 1.* Framework then you can register an event handler
with Exited to do the same thing as a above but without the anonymous
part.
--
Dave Sexton
"bjm" <cy**********@h otmail.comwrote in message
news:11******** *************@1 6g2000cwy.googl egroups.com...
I am writing a program that will automate a series of application
installations. I want to give the user the option of stopping the
program's execution in between installations (for example, give the
user the chance to stop the program after the second installation
before it continues on to the third installation). However, I want the
user to be able to start the installations and walk away as well, so I
can't ask the user if he wants to continue if that means execution will
stop and wait for his response. I thought of two ways to do this,
though there may be a better way I'm not thinking of.
First, I could have a button on my program's Form that says "Stop
Installation." I tried doing this, and having that button's click
event simply set a flag that says to stop execution after the current
installation. However, when an installation starts, I get an hour
glass and I am unable to hit the button that I created. If this is
going to work, I need to find a way to continue allowing the user to
enter input even while the program is running an installation (with the
Process class).
Second, I could pop up a dialog asking the user if he wants to
continue, which closes after X number of seconds without a response. I
think this would work, but I'm new to C# and I haven't found a
relativly easy way of doing this.
Does anyone have an idea of how I could accomplish this? Thank you in
advance!
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: qwweeeit |
last post by:
Hi all,
Elliot Temple on the 1 June wrote:
> How do I make Python press a button on a webpage? I looked at
> urllib, but I only see how to open a URL with that. I searched
> google but no luck.
> For example, google has a button <input type=submit value="Google
> Search" name=btnG> how would i make a script to press that button?
I have a similar target: web automation, which
|
by: Neil Ginsberg |
last post by:
I have a strange situation with my Access 2000 database. I have code in the
database which has worked fine for years, and now all of a sudden doesn't
work fine on one or two of my client's machines. The code opens MS Word
through Automation and then opens a particular Word doc. It's still working
fine on most machines; but on one or two of them, the user is getting an
Automation Error. The code used is as follows:
Dim objWord As...
|
by: Jimmer |
last post by:
I've got what should be an easy automation problem, but the solution
simply isn't coming to me.
I've got several public variables set up for automation as follows:
Public gappExcel As Excel.Application 'ADO Object for Excel
Automation
Public gstrExcelDir As String 'Source or Destination Directory
|
by: Lee Seung Hoo |
last post by:
hi~ :)
I need all information of "Automation" or "Automation Object"
what is that ?
why is it useful ?
How can I use that by C# or .Net Framework ?
|
by: a.theil |
last post by:
Please help!
I need a simple excel automation, just 2 write some files into excel.
I do:
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim oRng As Excel.Range
| |
by: Sharath |
last post by:
Quality Globe is Glad to Offer you the Fast Track course on
Automation,
QTP Basics and Advanced, and Quality Center
Starting Date: June 4th, 2007
Timings: 10 AM to 3:30 PM
Duration: 50 Hours
Location: BTM Layout 1st Stage, Bangalore
|
by: Sharath |
last post by:
"Inspired" by the huge success of our first two automation fast track
batches
We are forced to start third fast track automation batch
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++
Course on Automation, QTP Basics and Advanced, Quality Center and
project
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
by: Sharath |
last post by:
We are glad to inform you that
"Inspired" by the huge success of our first three automation fast
track
batches
We are forced to start fourth fast track automation batch
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Course on Automation, QTP Basics and Advanced, Quality Center and
project
|
by: Sharath |
last post by:
We are glad to inform you that
"Inspired" by the huge success of our first four automation fast
track
batches
We are forced to start fifth fast track automation batch
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Course on Automation, QTP Basics and Advanced, Quality Center and
project
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |