Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP 'waits' for change in directory 2

Status
Not open for further replies.

jbs

Programmer
Feb 19, 2000
121
US
I've been trying to find a way to write an asp that goes into a wait state until a file is saved to an otherwise empty folder on the server.

I'm able to do this in a standalone VBasic file using WIN32 function calls "FindFirstChangeNotification" and "WaitForSingleObject"; however I have no idea if or how to use these function calls in an asp.

I suspect that this type of function is rather popular ...sometimes it's called a drop-box function.

Anyway, if I can't use these WIN32 library calls in an ASP then does anyone have an idea of how I could accomplish the task?

thanks for the help.

/jerry
 
I hope there's something better, but all I can think of is "client pull" where you use something like:
Code:
<META HTTP-EQUIV=&quot;REFRESH&quot; CONTENT=&quot;30; URL=http://server/page.asp&quot;>
This would keep hitting &quot;page.asp&quot; until the code there found your file, then it would return a response page without the REFRESH in it.

I think this is the traditional method, due to the nature of ASP and the Web. I suggest you check the KB:

-- Q240774 - How to Enable Client Pull for Web Servers, Sites, and Folders

Hope this helps!
 
thanks, but I don't think it will work.... Here is some more detail on my problem:

The web user submits data via a standard post and an ASP saves the data to a file and then goes into a wait-state (or idle mode) while waiting for a response from a separate program which processes the data.

On a separate test system I have the HTML code working that requests text data from a user and then sends it to an ASP which saves the user data into a text file on the server. What I'm having difficutly with is finding a way to have the same ASP go into an idle state while waiting for a response from separate server-side application to process the data and store the result in a folder called 'responses'. The ASP should recognize that the response file has been placed in the response folder. The ASP then reads the response file and writes a 'task completed' message on the users screen.

There are some WIN32 library functions (is this the correct term) that I mentioned in the first posting that will place the calling program into an idle state until a change in the contents of a folder is recognized ...and then the program comes out of a wait state. I have this working in VBScript but it won't work in ASP...

Is there a way to call and use WIN32 kernal function calls from an ASP? How? If not, does anyone have any other ideas?

Thanks for the education on Client Pull. I'm sure I'll use it somewhere in the future but I don't think it will work here because it appears that Client Pull is triggered by a delay in time vice a software trigger (i.e. the directory of a folder has changed).

Any other ideas???

thanks for trying,

Jerry
 
See the below msg, but I think I can provide greater focus on the problem:

All I need is for my ASP to check a folder for a specific file name. If the file is in the folder then great (I know what to do ...). If the file is not in the folder then wait until the file shows up.

I suspect continually checking to see if the file is in the folder from a loop may drag down performance of the server so I'm hoping to put the ASP into a idle mode until the file shows up.

any ideas?

thanks,

/jerry
 
Jerry,

I'm sure there's a way to make API calls from ASP code, but I doubt that you can find any way to make a specific process in IIS (your asp page) go into a wait state from the API call since your asp page isn't the same thing as an singular exe or dll (or at least it's somehow different).

Putting the loop in the asp waiting for the file to get there is the first thing I thought of, but you are concerned about server performance being degraded. Are you expecting it to take a long time until the file gets there? I wouldn't think performance would be hit too bad, but I'm not sure.

Perhaps you could write a dll that would do the checking and while IT is looping, it could do some DO Events or use the Sleep API function. That might reduce the CPU usage for the overall process and your ASP code would simply be waiting for the method in the DLL to complete, thereby the ASP code wouldn't be using CPU over and over (I would think).
 
Even if you figure this out you may have other troubles if the file you're awaiting takes a long time to appear. You might want to look at:

-- Q261211 - HOWTO: Execute Long Running Queries from Active Server Pages

This article discusses how to use Server.ScriptTimeout and related matters.

ASP pages really are supposed to make only synchronous method calls. One way to do this of course would be to create your own &quot;helper object&quot; in VB, that does the &quot;hanging around&quot; you want and only returns when the file becomes available or upon a &quot;timeout.&quot; After all, error handling is very important - what if the file never materializes?

One caution: I believe there is a problem with using a timer control to manage the timeout function in a VB object of this type, so you may have to seek an alternate timing mechanism. I think I saw an article on this somewhere.

I haven't seen anything you might use to wait explicitly in an ASP page - things like DoEvents are explicitly NOT available.

Has anyone seen any event support in ASP outside of the ones you implement in global.asa like Session_OnStart?
 
I think I have a solution....please let me know what you think:

Have the ASP call a server-side DLL which contains the WIN32 API's that go into system idle mode until the directory structure of the folder is changed. When the file is changed then I'll check and see if the correct folder is there, if not I'll check for a preset timeout and either do a controled timeout or go back into wait state.

I know how to write the VB code to use the WIN32 API calls, however I do need to know the answer to the following question:

When the ASP calls the server-side DLL, will the ASP wait for the DLL to complete? This is a key item....

If so, how do I call a server-side DLL?

thanks,

Jerry
 
Jerry,

Yes, the ASP will wait until the method that it calls in the DLL completes.

As far as the code goes, it's something along these lines:

Code:
Dim objFileChecker
Dim bStatus

'FileChecker is the name of the VB project and FolderOperations is the name of the public cls in the proj.
Set objFileChecker = Server.CreateObject(&quot;FileChecker.FolderOperations&quot;)

bStatus = objFileCheck.FindFolder(&quot;newfoldername&quot;)

If bStatus = &quot;OK&quot; Then
    continue on...
Else
    Response.Write(&quot;There were problems...&quot;)
    Response.End
End If

The ASP will wait until the public method &quot;FindFolder&quot; completes before it will continue on with processing.

Create your project, compile it to a dll and register it on the server. Then you can instantiate it like above.

Glenn
 
Thank you. I think this dll method might do the trick. I'll reply and let you know.

I'm also a bit concerned about the DLL timing-out (is this possible? Is this setable?) and/or the ASP timing-out while waiting for the DLL to complete. But will cross that road when I get there.

Ok...I'm on my way...sounds like a server-side DLL will cause the ASP to &quot;wait&quot; while the DLL executes the WIN32 API's to sleep until directory structure changes.

I've never done a server-side DLL before...had only heard about the concepts. I may come back with some newbie questions but I think this method may work a result in some rather un-breakable/reliable code.

/jerry
 
I don't think there's anything to timeout the dll, but the client's browser might. In IE 4 (don't know about other versions or other browsers), the default time that the browser will wait for a response from the server before timing out is 5 minutes. This setting can be changed by modifying the client's registry (can't recall where, but I can find it at work if you need it). Hopefully, the process won't take nearly that long (or you'll have some ticked off users)!

As far as newbie (or is it nooob?) questions, that's no prob, but I guess I'd start a new thread if I were you - you might get more responses too.
 
just to play devils advocate... what if you dont have access to the server in order to register the dll. what do people think of

a) downloading the dll to the client so that it runs from there - slower etc. but would it work in principle

b) having code on the asp page that acts in a similar way to the redirect. not sure how this would work, but conceptually the ASP pages juggle between themselves with a pause, check the output directory and then direct the action accordingly (e.g. if try < 3then tryAgain.asp else if found then action.asp)?

just a thought...
m
Mark Saunders :)
 
Mark and Glenn,

Yes, I'll post any new questions/issues to a new thread. This one is getting long. Good idea.

I believe that this function, when done, could be a rather popular function for users. Submitting data from a web page to a server, having an asp grab the user data and submit it to a separate program and wait for the results to show up in a file....seems like it would be a useful program. I know I need something like this for several different situations.

Relying on a client-side DLL won't work in my current situation because a requirement that I have is that I can't install anything on the client workstations. I do however have an ability to install a server-side DLL on the web server.

I'm concerned that the redirect solution might drag down performance on the server as it constantly loops waiting for a resonse which could be microseconds or minutes. The ASP somehow needs to go into a wait state (system idle mode) and await a change in the directory structure of a particular folder (..there is a WIN32 API that does watch folder/sleep function).

Although I'm able to install a DLL on the server, a better solution would not require a custom DLL to be install on a server (i.e. it would be a better generic solution).

I've never tried to get an ASP to send parameters to a server-side DLL, but I'm going to try it later today or Monday (I'm still a bit of a newbie at this). I'll post the solution for others on this site (...and any questions if I run into a problem).

Any other ideas or method of solution w/o DLL?
Too bad the WIN32-API's can't be called directly from the ASP...I didn't know that when I started. The DLL solution will work for me.

thanks for the help

/jerry



 
not a solution, but a workaround? could you include a
Code:
submitDetailRequest.asp
which sends form details to the server and then brings up the
Code:
getRequestedDetails.asp[code] that includes a button title something to the effect of [i]Go see if the file is ready[/i] (imaganintive eh?) which - well i suppose you can guess.

this not only gets around the fact that having it done automatically is cumbersome but allows the user to wait as long as they see fit (maybe they have a traditionally fast ot slow network?) and also the [code]asp
can keep track of the number of tries etc. to allow only so many?

just a though anyways....
m Mark Saunders :)
 
or even have it automatically count to, say, 1 second then automatically try and then bring up an errorPage saying &quot;file not ready click here to retry&quot;.
cheers.
m Mark Saunders :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top