472,807 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,807 software developers and data experts.

VB.NET Windows Service Process.WaitForExit does not work

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
Dec 14 '07 #1
4 8708
radcaesar
759 Expert 512MB
Why u prefer to use WaitForExit() here. After the winword process's work has finished, destroy that object manually in your code.
Dec 14 '07 #2
radcaesar
759 Expert 512MB
If you call CloseMainWindow for a process that has a user interface, the request to the operating system to terminate the associated process might not be handled if the process is written to never enter its message loop.
Dec 14 '07 #3
The Windows Service must run totally in the background on our Windows Server. When we don't use the waitforexit step then the program continue running. The following step in our program is to move the created .PDF doc in "my documents" if we don't wait until that PDF document is created the program fails. I also think that closemainwindow is no solution for our program because it runs in the background.
Dec 14 '07 #4
radcaesar
759 Expert 512MB
Here is the solution for ur problem

http://www.itwebmonkey.com/blog/archive/2007/10/10/windows-services-threadpool-hell.aspx
Dec 14 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: darknessfish | last post by:
Ok, I'm trying to write a basic scp scheduler, which will occasionally scan a directory, and use cygwin's scp.exe to copy the files to a Unix box. After various problems, the set up I've got now...
2
by: Tobias Johansson | last post by:
Hello, I'm having what I believe a security problem to execute an executable file from a windows service in windows server 2003. It works fine in WIN XP SP2 The program(the service) itself...
1
by: John Crouse | last post by:
I am using the following code sucessfully on Windows 2000 and Windows XP. However, in WIndows 98 it seems to hang on the WaitForExit. What are my options here? MsgBox("Please be patient. This...
3
by: BROQ | last post by:
Hi, I am using a windows service to extract every hour a log from our mailserver in order to parse the logfile. To do this I used the folowing code: Shell("""C:\pscp"" -pw *******...
3
by: Jay | last post by:
hi i am jay from bangalore i have one problem ,can u please help me out. i have one windows application and one windows service. from windows application i have to call one process "gpg" to...
1
by: gaurav tyagi | last post by:
hi mahesh i am gaurav from bangalore i have one problem ,can u please help me out. i have one windows application and one windows service. from windows application i have to call one process...
0
by: Phil Galey | last post by:
In VB.NET, does the Process object not work fully from within a service application. It seems to be able to run the external .exe that it's supposed to run, but I do a WaitForExit followed by...
3
by: SR | last post by:
I have a requirement from a customer to run some command line applications from a service. I have most of my service coded and I've come across an issue with the important part of the application,...
5
by: andrew | last post by:
Hi, I have the following issue with the Thread.Abort(): The main thread creates a worker thread which waits on a process termination. void ThreadProc() { Process proc =...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.