Home All Groups Group Topic Archive Search About

To use ShellExecute or not?

Author
12 Jan 2006 8:40 PM
Terry Olsen
When starting a process, what is the difference between using
ShellExecute or not using it?

I need to start IE when a link is clicked in my app. I want as little
impact to my app as possible. What is the best method for this?

In my case I have it working in a chat application.  I use a RTB so that
the links are detected.  I click on the link and IE opens without
problem 99% of the time.

If a link is clicked at the exact moment text is being appended to the
RTB, the app crashes with a threading error.

So I guess I want to start the process and return from the call as fast
as possible to see if I can alleviate the problem.

Thanks for any help.

*** Sent via Developersdex http://www.developersdex.com ***

Author
12 Jan 2006 10:55 PM
Herfried K. Wagner [MVP]
"Terry Olsen" <tolse***@hotmail.com> schrieb:
> When starting a process, what is the difference between using
> ShellExecute or not using it?

What's the alternative?  Not starting anything or using an alternate method
to start the application?  I recommend to use
'System.Diagnostics.Process.Start' instead of p/invoke with the
'ShellExecute' function.

> I need to start IE when a link is clicked in my app. I want as little
> impact to my app as possible. What is the best method for this?
>
> In my case I have it working in a chat application.  I use a RTB so that
> the links are detected.  I click on the link and IE opens without
> problem 99% of the time.
>
> If a link is clicked at the exact moment text is being appended to the
> RTB, the app crashes with a threading error.

Are you adding the text to the textbox from another thread?  Are you sure
you are using 'Control.{Invoke, BeginInvoke, InvokeRequired}' to access the
control from the other thread instead of accessing it directly?

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
13 Jan 2006 2:10 AM
Terry Olsen
Here's the code that I call from the SocketReceiveCallback routine...

Delegate Sub ToChatWindowDelegate(ByVal msg As String)
Dim ChatDelegate As New ToChatWindowDelegate(AddressOf ToChatWindow)
Dim ChatObject(0) As Object
Private Sub ToChatWindow(ByVal msg As String)
If msg = "" Then Exit Sub
If txtChat.InvokeRequired Then
ChatObject(0) = msg
txtChat.Invoke(ChatDelegate, ChatObject)
Else
txtChat.AppendText(msg)
End If
End Sub

Here's the code for the LinkClicked event
Private Sub txtChat_LinkClicked(ByVal sender As Object, ByVal e As
System.Windows.Forms.LinkClickedEventArgs) Handles txtChat.LinkClicked
Dim pi As New ProcessStartInfo(e.LinkText)
Process.Start(pi)
End Sub

What I'm wondering is what is the difference between using
pi.UseShellExecute=True and pi.UseShellExecute=False?

Which is better when all you want is to spawn an IE instance and get back as
quickly as possible?

Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:%235lU5s8FGHA.1312@TK2MSFTNGP09.phx.gbl...
> "Terry Olsen" <tolse***@hotmail.com> schrieb:
>> When starting a process, what is the difference between using
>> ShellExecute or not using it?
>
> What's the alternative?  Not starting anything or using an alternate
> method to start the application?  I recommend to use
> 'System.Diagnostics.Process.Start' instead of p/invoke with the
> 'ShellExecute' function.
>
>> I need to start IE when a link is clicked in my app. I want as little
>> impact to my app as possible. What is the best method for this?
>>
>> In my case I have it working in a chat application.  I use a RTB so that
>> the links are detected.  I click on the link and IE opens without
>> problem 99% of the time.
>>
>> If a link is clicked at the exact moment text is being appended to the
>> RTB, the app crashes with a threading error.
>
> Are you adding the text to the textbox from another thread?  Are you sure
> you are using 'Control.{Invoke, BeginInvoke, InvokeRequired}' to access
> the control from the other thread instead of accessing it directly?
>
> --
> M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
> V B   <URL:http://classicvb.org/petition/>