S
Stephen Miller
I have an ASP.Net application that sends a NetworkStream to a .Net
Service, which has a TcpListener listening on a port for the ASP.Net
client. When it receives a request it creates a new thread with the
AddressOf a class that runs a long data intensive process that can
take between 1-15 minutes and results in the creation of a uniquely
named file.
Meanwhile, I want my ASP.Net application to sit and wait until the
file appears at a given location (signalling that the worker thread
has ended) and then resume processing. I have built a .Net Service to
handle this processing because I was finding that IIS was running into
memory problems, when processing multiple requests.
Anyway, my problem is getting the ASP.Net to wait and then resume when
the file appears. To prevent timeout, I have added '<httpRuntime
executionTimeout="10000">' to the Web.Config file I also modified the
ASP Script timeout in IIS (Select virtual directory > 'Properties' >
'Configuration' button >'App Options' tab) and set that to 10000
seconds.
1. I have experimented with a FileSystemWatcher:
'-- Suspend processing until file appears
Dim oWatcher As New FileSystemWatcher('c:\myPath\', 'myFile.dat')
Dim oResult As WaitForChangedResult
oResult = oWatcher.WaitForChanged(Created)
'-- Resume processing
.... and this works fine for the first request, but fails for any
subsequent concurrent requests, hanging at the WaitForChanged event
long after the file is created. I have also found that if a large file
is being created the WaitForChanged event is triggered before the file
is finished writing to disk, resulting in (trappable) file access
errors.
2. I though it might then be easier to simply use a Do Loop, checking
until the File.Exists is true, with a Thread.Sleep(1000) for each
iteration:
'-- loop until file appears
Dim iSeconds As Long
Do Until File.Exists("c:\myPath\myFile.dat") = True
iSeconds += 1
Threading.Thread.Sleep(1000) '-- Sleep for 1 second
Loop
'-- Resume processing
.... however, I am finding that after 60-90 seconds, this fails on the
Thread.Sleep(1000) line, with the error message "Thread was being
aborted".
I am also finding that when this error throws to an exception, the
asp.net app appears to hang. In the catch block I have a simple
response.write to return the error message and I have tried adding a
response.end, but it won't die.
So my question is, what is the best way to suspend processing in an
asp.net application (for between 1-15 minutes), while a file is
generated by another process.
Thanks,
Stephen
Service, which has a TcpListener listening on a port for the ASP.Net
client. When it receives a request it creates a new thread with the
AddressOf a class that runs a long data intensive process that can
take between 1-15 minutes and results in the creation of a uniquely
named file.
Meanwhile, I want my ASP.Net application to sit and wait until the
file appears at a given location (signalling that the worker thread
has ended) and then resume processing. I have built a .Net Service to
handle this processing because I was finding that IIS was running into
memory problems, when processing multiple requests.
Anyway, my problem is getting the ASP.Net to wait and then resume when
the file appears. To prevent timeout, I have added '<httpRuntime
executionTimeout="10000">' to the Web.Config file I also modified the
ASP Script timeout in IIS (Select virtual directory > 'Properties' >
'Configuration' button >'App Options' tab) and set that to 10000
seconds.
1. I have experimented with a FileSystemWatcher:
'-- Suspend processing until file appears
Dim oWatcher As New FileSystemWatcher('c:\myPath\', 'myFile.dat')
Dim oResult As WaitForChangedResult
oResult = oWatcher.WaitForChanged(Created)
'-- Resume processing
.... and this works fine for the first request, but fails for any
subsequent concurrent requests, hanging at the WaitForChanged event
long after the file is created. I have also found that if a large file
is being created the WaitForChanged event is triggered before the file
is finished writing to disk, resulting in (trappable) file access
errors.
2. I though it might then be easier to simply use a Do Loop, checking
until the File.Exists is true, with a Thread.Sleep(1000) for each
iteration:
'-- loop until file appears
Dim iSeconds As Long
Do Until File.Exists("c:\myPath\myFile.dat") = True
iSeconds += 1
Threading.Thread.Sleep(1000) '-- Sleep for 1 second
Loop
'-- Resume processing
.... however, I am finding that after 60-90 seconds, this fails on the
Thread.Sleep(1000) line, with the error message "Thread was being
aborted".
I am also finding that when this error throws to an exception, the
asp.net app appears to hang. In the catch block I have a simple
response.write to return the error message and I have tried adding a
response.end, but it won't die.
So my question is, what is the best way to suspend processing in an
asp.net application (for between 1-15 minutes), while a file is
generated by another process.
Thanks,
Stephen