NetTalk Central

NetTalk Web Server => Web Server - Ask For Help => Topic started by: billbarker on March 20, 2015, 07:19:53 AM

Title: Timer procedure from the webserver
Post by: billbarker on March 20, 2015, 07:19:53 AM
Is there any reason why I should not  invoke a new thread from the webserver window, on a timer?

I want to add entries to an email queue during normal processing by users (it seems to take a while to send an email) so I thought I'd just slot the details into a queue, and process this on a timer invoked process, from the main webserver window?

Title: Re: Timer procedure from the webserver
Post by: Keith on March 20, 2015, 12:08:45 PM
Bill

Great question.  I was contemplating exactly the same approach.  In my case I want to send an email based on actions a user takes on a Form (to change a critical field for example).  The user is not sending the mail but the program logic determines that one is required.  So I was going to add the details to a queue or file and run a process off a Webserver timer to send the mails and mark them (in the file) as 'Sent'.

I do have an unrelated process running off a Timer which periodically creates a CSV file and I guess that unless you can have two Timers that you would just include logic to either perform both actions with the same period or a logic fudge to perform them out of sync.

Haven't coded it yet but will be interested in any advice.

Keith
Title: Re: Timer procedure from the webserver
Post by: kevin plummer on March 22, 2015, 02:33:00 PM
Hi Bill,

the easier approach is to probably just start a new thread in your code to send the email.
Title: Re: Timer procedure from the webserver
Post by: Bruce on March 22, 2015, 09:54:13 PM
>> Is there any reason why I should not  invoke a new thread from the webserver window, on a timer?

no. You can start new threads from the WebServer window if you like. And indeed _anything_ (and I mean _AnyThing_) with a window (including reports) MUST be on a separate thread. ANY other window opening from the WebServer WILL cause the server to break.

>> Kevin: the easier approach is to probably just start a new thread in your code to send the email.

yes, remember each request is already on it's own thread. You can "use" this thread if you like. To signify to the browser that the reply is complete (and therefore can be displayed to the end user) you do a
p_web.ReplyComplete()
At this point the connection to the browser is ended.
You can now continue to use the thread, send an email or whatever.

Cheers
Bruce
Title: Re: Timer procedure from the webserver
Post by: billbarker on March 23, 2015, 02:10:46 AM
Great.. I'll give it a try (just thought I'd better check!)