Question Start(FileName As String) issue

Budius

Well-known member
Joined
Aug 6, 2010
Messages
137
Location
UK
Programming Experience
3-5
Hi,

I have a quite simple application that is having some random locks up.

It's just a few text fields that the user fill it up, 3 sets of Radio buttons, one of them with flags to chose the language and click the PDF button.
The application uses iTextsharp to load a PDf template, insert the text into it, depending on the language loads some extra text from a .xml file, and depending on the radio button removes the images from the PDF, closes the pdfstamper and uses
VB.NET:
Start(FileName)                      ' Opens the file with default application
Me.Cursor = Cursors.Default
Me.Close()
to open the file with whatever PDF application the user have installed and closes itself.

Sounds simple, but after the application is installed in the machine (never in debugging mode) it randomly locks up the application.
I tried re-publish the application commenting out the Start(filename) line and the thing stopped locking. And I double checked it, re-publish with the line again and it locked after just a few attempts.

Any ideas??

=======
Edit:

carry on testing this, this one is just to check if the iTextSharp is interfering with the Start in anyway, I completely comment out the whole pdf processing, what the application do OnClick of the button is:
VB.NET:
        Dim DataLogo As Boolean = Static15.Checked
        Dim DataOnly As Boolean = Static16.Checked
        Dim LogoOnly As Boolean = Static17.Checked

        Dim FileName As String = Application.StartupPath & "\Labels.pdf"

        Me.Cursor = Cursors.WaitCursor

        Try
            Start(FileName)                      ' Opens the file with default application
        Catch ex As Exception
            Debug.Print(ex.Message)
        End Try

        Me.Cursor = Cursors.Default
        Me.Close()

and the installed application still locks up.
any ideas?
 
Last edited:
I didn't solve it but I kinda managed to cast some light into the mystery...
if you google "vb.net process.start hangs" you'll see that it's not an uncommon thing for the start to stuck the whole damn thing.

in some of those googling I found the arguments to start the cmd.exe and execute the .pdf from there using
VB.NET:
            Dim p As New ProcessStartInfo
            p.FileName = "cmd.exe"
            p.Arguments = "/c start " & FileName
            p.UseShellExecute = False
            Process.Start(p)

On the thread I found this code there was some discussion about how the UseShellExecute = false would make the application not lock
but the fact is that now my application is not locking but cmd.exe is locking, duh!

Considering how often this program is to be used, how often the execution locks and the fact that it locks AFTER the pdf opens, I'm tempted to just include a p.WindowStyle = ProcessWindowStyle.Hidden to hide the locked window and walk away from it.

But before I do it, does anyone knows how I can get the reference to that cmd.exe and kill its process from my app?
So even thou I'm not avoiding it to lock at least I'll kill it before anyone sees it.

====
edit:

ok found: http://www.vbdotnetforums.com/windows-services/4022-kill-specific-process.html

so I'll start the cmd.exe it wil trigger my pdf I'll make a little Sleep() and Try kill the process.
 
Last edited:
Back
Top