Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / December 2004

Tip: Looking for answers? Try searching our database.

How to create a new app instance with Process

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joe - 20 Dec 2004 15:47 GMT
I am using the Process class to start the associated program for a specific
file. The Process.Start method reuses an existing running instance of the
Process, and that's not want I want. I always want a new unique instance of
the application to start.
Mujtaba Syed - 20 Dec 2004 16:25 GMT
Joe:

There are 3 static overloads of the Start method in the Process class. Try
those.

Thanks,
Mujtaba.

> I am using the Process class to start the associated program for a specific
> file. The Process.Start method reuses an existing running instance of the
> Process, and that's not want I want. I always want a new unique instance of
> the application to start.
Joe - 20 Dec 2004 16:35 GMT
Thanks, but all of the overloads do the same thing - they reuse a process if
it is already running, and I alwasy want to create an new instance of the
process. I'm trying to display an XML or HTML file in IE (or whatever program
is associated with XML on the user's system). I don't want an existing
instance of IE to load the XML because I want the user to close the
application before returning to my app. Closing an open instance would be a
major annoyance if they want their browse left open.

> Joe:
>
[quoted text clipped - 10 lines]
> of
> > the application to start.
Mujtaba Syed - 20 Dec 2004 17:11 GMT
Hi Joe:

See the example here
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemdiagnosticsprocessclassstarttopic.asp


Thanks,
Mujtaba.

> Thanks, but all of the overloads do the same thing - they reuse a process if
> it is already running, and I alwasy want to create an new instance of the
[quoted text clipped - 18 lines]
> > of
> > > the application to start.
Shariq Khan - 20 Dec 2004 18:33 GMT
Joe:

Try this class:

Imports System.Diagnostics
Imports System.IO

Public Class ShellDocument

   Private Declare Function FindExecutable Lib "shell32.dll" Alias
"FindExecutableA" _
       (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult
As System.Text.StringBuilder) As Integer

   Public Shared Function Start(ByVal fileName As String) As Process
       Dim sExeName As String = ""
       Dim sTempFile As String = Path.GetTempPath() +
Guid.NewGuid.ToString("B") + ".htm"
       Dim oFile As New FileStream(sTempFile, IO.FileMode.Create,
IO.FileAccess.Write, IO.FileShare.Write)
       Try
           Dim oStr As New System.Text.StringBuilder
           oStr.Append(Chr(32), 254)
           Dim iResult As Integer = FindExecutable(sTempFile, "", oStr)
           sExeName = oStr.ToString()
       Finally
           oFile.Close()
           IO.File.Delete(sTempFile)
       End Try

       Dim info As New System.Diagnostics.ProcessStartInfo(sExeName)
       info.Arguments = fileName

       Return System.Diagnostics.Process.Start(info)
   End Function
End Class

Shariq Khan
shariq@shariqkhan.com

>I am using the Process class to start the associated program for a specific
> file. The Process.Start method reuses an existing running instance of the
> Process, and that's not want I want. I always want a new unique instance
> of
> the application to start.
Joe - 20 Dec 2004 18:49 GMT
This doesn't do it either. I don't want to close the currently running
instance, I want to create my own instance of the app (whatever the
associated program is) and then wait for the user to close it manually.
Thanks though.

> Joe:
>
[quoted text clipped - 41 lines]
> > of
> > the application to start.
Shariq Khan - 20 Dec 2004 19:10 GMT
If you look closely, the function returns a System.Diagnostics.Process
object. You can call the WaitForExit method on that object to wait till that
process closes. See
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemdiagnosticsprocessclasswaitforexittopic.asp


You can also setup a handler for the OnExited event on this process object
which will be fired when the process exits.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemdiagnosticsprocessclasswaitforexittopic.asp


Hope this helps.
Cheers,

Shariq Khan
shariq@shariqkhan.com

> This doesn't do it either. I don't want to close the currently running
> instance, I want to create my own instance of the app (whatever the
[quoted text clipped - 50 lines]
>> > of
>> > the application to start.
Joe - 20 Dec 2004 19:10 GMT
Yes, sorry, this does do what I want, thank you.

> Joe:
>
[quoted text clipped - 41 lines]
> > of
> > the application to start.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.