Using C# to launch apps

G

Guest

I am using a C# winform to launch some apps for our students. Basically the
user hits a button the form hides and the app is launched. When the app
exits, the form is unhidden. I have a question on two things. From what I
understand since I am starting the program from the Process.Start it is on a
separate thread and this is really not a problem. Secondly what is the best
way to work this form. Do I dispose of the form when I start the app or do I
hide it? The idea here is to keep student working on just what the buttons
allow.
 
N

Nicholas Paldino [.NET/C# MVP]

Christopher,

I think a good idea here would be to launch the Process from a separate
thread. You can then wait until the process is done on that thread.

Before you launch the process on another thread, from the UI thread, you
would hide the form. A good thing to do would be to have a NotifyIcon in
the tray.

In the thread waiting on the process, when the process completes, you
would call Invoke on the Form, passing a delegate to call the Show method
(or some other method indicating to proceed to the next step). Then, you
can continue from there.

Hope this helps.
 
Y

Yosh

Christopher,

It sounds like your application is like a "DashBoard" form where students
have the ability to run applications by clicking buttons on the dashboard
form. My suggestion is to hide your "DashBoard" form when the user clicks
the button that runs the application. When the user quits the application,
then you can show your "DashBoard" form again.

You say you are using the Process.Start method to run the application. This
works great. You can also subscribe to the Process "Exited" event. This gets
fired when the process exits (student closes the app) and show your
"DashBoard" form. =0}

Hope this makes sense.

Yosh.
 
G

Guest

Do you have a good example of threading is this manner? I am very new to the
threading concept and have a hard time grasping it.

Nicholas Paldino said:
Christopher,

I think a good idea here would be to launch the Process from a separate
thread. You can then wait until the process is done on that thread.

Before you launch the process on another thread, from the UI thread, you
would hide the form. A good thing to do would be to have a NotifyIcon in
the tray.

In the thread waiting on the process, when the process completes, you
would call Invoke on the Form, passing a delegate to call the Show method
(or some other method indicating to proceed to the next step). Then, you
can continue from there.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Christopher C said:
I am using a C# winform to launch some apps for our students. Basically the
user hits a button the form hides and the app is launched. When the app
exits, the form is unhidden. I have a question on two things. From what I
understand since I am starting the program from the Process.Start it is on
a
separate thread and this is really not a problem. Secondly what is the
best
way to work this form. Do I dispose of the form when I start the app or do
I
hide it? The idea here is to keep student working on just what the buttons
allow.
 
O

Ollie Riches

Jonny Skeet has some very good examples:

http://www.yoda.arachsys.com/csharp/threads/

HTH

Ollie Riches
Christopher C said:
Do you have a good example of threading is this manner? I am very new to
the
threading concept and have a hard time grasping it.

Nicholas Paldino said:
Christopher,

I think a good idea here would be to launch the Process from a
separate
thread. You can then wait until the process is done on that thread.

Before you launch the process on another thread, from the UI thread,
you
would hide the form. A good thing to do would be to have a NotifyIcon in
the tray.

In the thread waiting on the process, when the process completes, you
would call Invoke on the Form, passing a delegate to call the Show method
(or some other method indicating to proceed to the next step). Then, you
can continue from there.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Christopher C said:
I am using a C# winform to launch some apps for our students. Basically
the
user hits a button the form hides and the app is launched. When the app
exits, the form is unhidden. I have a question on two things. From what
I
understand since I am starting the program from the Process.Start it is
on
a
separate thread and this is really not a problem. Secondly what is the
best
way to work this form. Do I dispose of the form when I start the app or
do
I
hide it? The idea here is to keep student working on just what the
buttons
allow.
 
G

Guest

Here's the MSDN events tutorial:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkEventsTutorial.asp

And here's the MSDN C# Threading tutorial:

http://msdn.microsoft.com/library/d...y/en-us/csref/html/vcwlkThreadingTutorial.asp

If you follow Nicholas's suggestion of spinning off a worker thread here's
some code that can help with launching the process. This code configures how
the launched process's window should appear {for my needs I specifically
wanted shell execution and I wanted the launched process's window hidden} and
then it waits for the process to complete.

Do NOT use this code from the GUI thread - it's never good to block a GUI
thread - this code is for a worker thread. Also note the "using" clause, it
is important to dispose of the process instance after the process finishes
because the process instance keeps an open handle on the underlying OS until
it is explicitly disposed:

private void Execute(string exeName, string args)
{
using (process = new Process())
{
process.StartInfo = new ProcessStartInfo(exeName, args);
process.StartInfo.WorkingDirectory = Path.GetDirectoryName(exeName);
process.StartInfo.ErrorDialog = false;
process.StartInfo.UseShellExecute = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.Start();
process.WaitForExit();
}
}






Christopher C said:
Do you have a good example of threading is this manner? I am very new to the
threading concept and have a hard time grasping it.

Nicholas Paldino said:
Christopher,

I think a good idea here would be to launch the Process from a separate
thread. You can then wait until the process is done on that thread.

Before you launch the process on another thread, from the UI thread, you
would hide the form. A good thing to do would be to have a NotifyIcon in
the tray.

In the thread waiting on the process, when the process completes, you
would call Invoke on the Form, passing a delegate to call the Show method
(or some other method indicating to proceed to the next step). Then, you
can continue from there.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Christopher C said:
I am using a C# winform to launch some apps for our students. Basically the
user hits a button the form hides and the app is launched. When the app
exits, the form is unhidden. I have a question on two things. From what I
understand since I am starting the program from the Process.Start it is on
a
separate thread and this is really not a problem. Secondly what is the
best
way to work this form. Do I dispose of the form when I start the app or do
I
hide it? The idea here is to keep student working on just what the buttons
allow.
 
G

Guest

I am looking at doing a Async call for the new process thread. Is there any
reason this would be a bad idea or am I on the right track?

Richard said:
Here's the MSDN events tutorial:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkEventsTutorial.asp

And here's the MSDN C# Threading tutorial:

http://msdn.microsoft.com/library/d...y/en-us/csref/html/vcwlkThreadingTutorial.asp

If you follow Nicholas's suggestion of spinning off a worker thread here's
some code that can help with launching the process. This code configures how
the launched process's window should appear {for my needs I specifically
wanted shell execution and I wanted the launched process's window hidden} and
then it waits for the process to complete.

Do NOT use this code from the GUI thread - it's never good to block a GUI
thread - this code is for a worker thread. Also note the "using" clause, it
is important to dispose of the process instance after the process finishes
because the process instance keeps an open handle on the underlying OS until
it is explicitly disposed:

private void Execute(string exeName, string args)
{
using (process = new Process())
{
process.StartInfo = new ProcessStartInfo(exeName, args);
process.StartInfo.WorkingDirectory = Path.GetDirectoryName(exeName);
process.StartInfo.ErrorDialog = false;
process.StartInfo.UseShellExecute = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.Start();
process.WaitForExit();
}
}






Christopher C said:
Do you have a good example of threading is this manner? I am very new to the
threading concept and have a hard time grasping it.

Nicholas Paldino said:
Christopher,

I think a good idea here would be to launch the Process from a separate
thread. You can then wait until the process is done on that thread.

Before you launch the process on another thread, from the UI thread, you
would hide the form. A good thing to do would be to have a NotifyIcon in
the tray.

In the thread waiting on the process, when the process completes, you
would call Invoke on the Form, passing a delegate to call the Show method
(or some other method indicating to proceed to the next step). Then, you
can continue from there.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I am using a C# winform to launch some apps for our students. Basically the
user hits a button the form hides and the app is launched. When the app
exits, the form is unhidden. I have a question on two things. From what I
understand since I am starting the program from the Process.Start it is on
a
separate thread and this is really not a problem. Secondly what is the
best
way to work this form. Do I dispose of the form when I start the app or do
I
hide it? The idea here is to keep student working on just what the buttons
allow.
 

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