Hello,
This is my first post. I searched on the internet for answers but I was unable to solve my problem. So I hope that you guy's can help me with my VB.NET problem
I tried to create a windows service that converts MS Word Files into .PDF files and after that we want to zip the .PDF files.
Our code:
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
watchfolder = New System.IO.FileSystemWatcher
'this is the path to monitor
watchfolder.Path = "D:\sea78\siebsrvr\ServerDataSrc\files\"
'Add a Filter for created files
watchfolder.NotifyFilter = watchfolder.NotifyFilter Or IO.NotifyFilters.FileName
'search only for .doc files
watchfolder.Filter = "*.doc"
' add the handler to each event
AddHandler watchfolder.Created, AddressOf DOC_Created
'Set this property to true to start watching
watchfolder.EnableRaisingEvents = True
End Sub
==> the code above creates a watched folder which works fine!
Private Sub DOC_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs)
Dim sFileName As String
sFileName = e.Name.Substring(7, 30).ToUpper()
If e.ChangeType = IO.WatcherChangeTypes.Created Then
'give the application some time to complete the word doc
System.Threading.Thread.Sleep(2000)
'Print/Convert .DOC to .PDF
Dim strword As String = "C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE"
Dim wordProc As Process = Process.Start(strword, "D:\sea78\siebsrvr\ServerDataSrc\files\Merged_ " & sFileName & ".doc /q /n /mFilePrintDefault /mFileExit")
'wordProc.WaitForExit()
System.Threading.Thread.Sleep(5000)
'wordProc.Kill()
'wordProc.Close()
'Rename and move .PDF to HELP folder
Dim fMovePDF As New FileInfo("C:\Documents and Settings\siebelo\My Documents\Merged_" & sFileName & ".pdf")
fMovePDF.MoveTo("D:\sea78\siebsrvr\HELP\" & sFileName & ".pdf")
System.Threading.Thread.Sleep(2000)
'Zip .PDF to .SAF file
Dim strZip As String = "D:\sea78\siebsrvr\BIN\ssezip.exe"
Dim zipProc As Process = Process.Start(strZip, "D:\sea78\siebsrvr\HELP\" & sFileName & ".SAF D:\sea78\siebsrvr\HELP\" & sFileName & ".pdf")
System.Threading.Thread.Sleep(2000)
'zipProc.Kill()
'zipProc.WaitForExit()
'zipProc.Close()
'Copy .SAF file to S:\att folder
Dim fCopySAF As New FileInfo("D:\sea78\siebsrvr\HELP\" & sFileName & ".SAF")
fCopySAF.CopyTo("S:\att\" & sFileName & ".SAF", True)
System.Threading.Thread.Sleep(2000)
'Delete temp files
Dim FiletoDel As String = "D:\sea78\siebsrvr\HELP\" & sFileName & ".pdf"
System.IO.File.Delete(FiletoDel)
FiletoDel = "D:\sea78\siebsrvr\HELP\" & sFileName & ".SAF"
System.IO.File.Delete(FiletoDel)
'FiletoDel = "D:\sea78\siebsrvr\ServerDataSrc\files\Merged_ " & sFileName & ".doc"
'System.IO.File.Delete(FiletoDel)
'update siebel record
Dim strSql As String = "D:\oracle\ora92\bin\sqlplusw.exe"
Dim SqlProc As Process = Process.Start(strSql, "siebel/siebel@siebdev.world @" & ControlChars.Quote & "D:\sea78\siebsrvr\IBM PDF Creator\SET_PDF_FILEEXT.sql" & ControlChars.Quote & " " & sFileName)
'SqlProc.WaitForExit()
As you can see we tried a few things. First we created a normal windows application and it works fine with the process.waitforexit() but in the windows service project the process.waitforexit() won't work. We can see that winword.exe won't close in the taskmanager. We also know that our windows service hangs because winword.exe does not close. When we close it in the taskbar the next lines will be executed but hangs again when we launch the ssezip.exe program (again that application won't close)
Any help and suggestions are welcome
Steven