Geeks With Blogs
The Life and Times of a Dev Yes, we're really that weird

So I’m working on a project that requires that we create a custom URL Protocol so that when users click on a link in the web browser, an agent on their machine opens a file in the appropriate application on their computer from a network share inside of the corporation.

For example, say they click on a link to a PDF in their browser that’s at path \\MyServer\Files\MyPdfFile.pdf.  This agent will launch the file using Process.Start(“\\MyServer\Files\MyPdfFile.pdf”) and the OS takes over, Adobe’s products are loaded, and the file is displayed.

The way that the custom url protocol works is that it launches a new instance of the associated agent every time the link is clicked.  Having many of these running isn’t desirable, since we’re starting the agent on login, so to handle that, we check to see if another is running, and if it is, we make a call to it using WCF’s net.tcp, pass it the file to open, and then shut down the second instance of the agent, while the first instance opens the file.

Everything worked great until we tried to launch Excel files.  For some reason we are unable to determine, and on multiple computers and OS’s, Excel takes up to 30 seconds to launch, even though if you open the file up directly, it opens instantly. We think it’s some kind of security check.

We tried several things, including using a startinfo.UseShellExecute=true setting, and nothing worked.  If you made a button in the agent that called the code to launch, it was instant, but if it was the agent calling itself and then trying to launch Excel, it took 30 seconds.  Annoying.

To fix it, all we had to do was have the call to launch put on a background thread.  Task.Run(() => Launch(filename)) made it work.

Why does changing the thread make a difference?  I have no idea. 

If you run into this, though, at least you’ll know the quick way to make it behave.

Posted on Thursday, March 24, 2016 2:07 PM | Back to top

Comments on this post: Fun with Excel, ShellExecuteEx and CreateProcess

# re: Fun with Excel, ShellExecuteEx and CreateProcess
Requesting Gravatar...
Thank you for sharing this information here. I was searching on this topic in Google and found the information in this website.
Left by Dencil Pumps on Mar 25, 2016 4:25 AM

# Help with Assignments Online
Requesting Gravatar...

I am a Advance Excel Student and I have heard a lot about Dissertation problem of Students and I would like to recommend Affordable Assignment Help is one of the best for helping purposes. They can do all the stuff on time and rates are really reasonable.
For more:
Left by Niamh Katee on Aug 12, 2016 4:14 AM

# re: Fun with Excel, ShellExecuteEx and CreateProcess
Requesting Gravatar...
we all wish u new year status
Left by daniels danny on Nov 14, 2016 9:51 AM

# LG G7 Release Date
Requesting Gravatar...
While we have been burdened with expectations of a successful successor to the LG G6, we have been saying for some time that this new phone will be the one phone which will rule them all.
LG has already been on a roll and we expect that the G7 will also be up to the mark. Want to know more about it? Check out this website LG G7 Release Date
Left by Samuel Dell on May 08, 2017 7:13 AM

# re: Fun with Excel, ShellExecuteEx and CreateProcess
Requesting Gravatar...
Seeking to enjoy movies or daily TV streaming simpler than exploring many useless websites or apps? Get app showbox for apple to receive all the most excellent functions, contents and slightest concern.
Left by apkpipe on May 29, 2017 4:11 AM

# re: Fun with Excel, ShellExecuteEx and CreateProcess
Requesting Gravatar...
Left by anu nia on Mar 01, 2018 11:05 PM

Your comment:
 (will show your gravatar)

Copyright © Robert May | Powered by: