469,631 Members | 1,340 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

Using C# to launch apps

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.
Nov 17 '05 #1
7 2395
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]
- mv*@spam.guard.caspershouse.com

"Christopher C" <Ch**********@discussions.microsoft.com> wrote in message
news:28**********************************@microsof t.com...
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.

Nov 17 '05 #2
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.


"Christopher C" <Ch**********@discussions.microsoft.com> wrote in message
news:28**********************************@microsof t.com...
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.

Nov 17 '05 #3
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"Christopher C" <Ch**********@discussions.microsoft.com> wrote in message
news:28**********************************@microsof t.com...
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.


Nov 17 '05 #4
Do you have a good article on events? I have limited knowledge of this.

"Yosh" wrote:
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.


"Christopher C" <Ch**********@discussions.microsoft.com> wrote in message
news:28**********************************@microsof t.com...
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.


Nov 17 '05 #5
Jonny Skeet has some very good examples:

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

HTH

Ollie Riches
"Christopher C" <Ch**********@discussions.microsoft.com> wrote in message
news:2B**********************************@microsof t.com...
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"Christopher C" <Ch**********@discussions.microsoft.com> wrote in message
news:28**********************************@microsof t.com...
>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.


Nov 17 '05 #6

Here's the MSDN events tutorial:

http://msdn.microsoft.com/library/de...tsTutorial.asp

And here's the MSDN C# Threading tutorial:

http://msdn.microsoft.com/library/de...ngTutorial.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" wrote:
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"Christopher C" <Ch**********@discussions.microsoft.com> wrote in message
news:28**********************************@microsof t.com...
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.


Nov 17 '05 #7
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" wrote:

Here's the MSDN events tutorial:

http://msdn.microsoft.com/library/de...tsTutorial.asp

And here's the MSDN C# Threading tutorial:

http://msdn.microsoft.com/library/de...ngTutorial.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" wrote:
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"Christopher C" <Ch**********@discussions.microsoft.com> wrote in message
news:28**********************************@microsof t.com...
>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.

Nov 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by akantrowitz | last post: by
1 post views Thread by teejayem | last post: by
3 posts views Thread by =?Utf-8?B?QnJpYW4gTmljaG9sc29u?= | last post: by
6 posts views Thread by tempnode | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.