Re: HTTPContext Session and worker thread (Fire and Forget)



Googling a bit I have found that, I could:

- Once the page is loaded on the client side, make the request via script
services:

- Good thing: I will get notified once the request has been completed
without affecting my page.

- Bad thing: I have to wait for the page to be served on the client side
and then launch from there the script service petition.

I could implement as well a custom HttpHandler, but I think we would have
the same scenario.

Any extra thought about this? Thanks, Regards
Braulio



/// ------------------------------
/// Braulio Diez
///
/// http://www.tipsdotnet.com
/// ------------------------------




"George Ter-Saakov" wrote:

I am not sure about implications of passing Session to another thread but in
general I would not do that. Unless you want to troubleshoot your
application for the rest of your life :)
---------------------------------------------------
I would create something more robust.

1. Table in DB tblJobs(JobId, Owner, Status, TimeIn, TimeOut, MessageIn,
MessageOut)
Status = (Pending, Processing, Completed)
Owner is who kciked off the job. List specific UserId

2. To kick of the job you insert record into tblJobs with MessageIn having
XML serialized object needed to do the job (like bunch of parameters). Also
you would need to increase "ActiveJobs" counter in the sesssion.

3. Some External Thread/External Process/MSMQ (your choice) pooling Jobs
to-do from the table and working on it. After it's done it populates TimeOut
and MessageOut with XML serialized object of the result of the job.

4. Your aspx page is checking for ActiveJobs counter if it's not 0 then
checks result of the job(s) submitted by that Owner. Updates Session if job
is completed.....

--------------------------------------------------------------------
PS: In order to avoid multithreading/multiprocessing problems you must be
careful. Always do optimistic locking when updating tblJobs
Meaning that if you have more than one process/thread that pools tblJobs for
new jobs then folow following steps (actually always do that)

1. Get a pending job "SELECT ... FROM tblJobs Where status = Pending"
2. Set status to processing "UPDATE tblJobs SET status=Processing WHERE
JobId=1 AND status = Pending"
3. Check that 1 (not 0) records were updated. SqlCommand.ExecuteNonQuery
returns that.
4. If returned value was 1 then proceed to execute job. If it's 0 then do
not execute job cause it was grabbed by other pooling thread between step 1
and 2.


George.








George.


"Braulio Diez" <braulio121NOSPAM@xxxxxxxx> wrote in message
news:8C9C007B-C93C-43BC-AC61-E7F57149FDCA@xxxxxxxxxxxxxxxx
Hello,

In my ASP .net application in one of the pages I have to fire a process
that takes quite long to execute, my idea is to execute this using the
fire
and forget pattern (let the page to process and respond, but start a
worker
thread to execute the process, it takes 1 minute to execute or something
like
that).

All this I got it more or less
working(http://www.eggheadcafe.com/articles/20050818.asp).

Now comes the question...

My idea is to store the result in a session varialbe (later on using
script services I will play with that value), is a good approach to pass
as a
parameter for the worker thread the HTTPContext or Session ? Too risky?(I
know an additional restriction is to use a static method :-() What other
approaches could I take?

Thanks, Regards
Braulio

/// ------------------------------
/// Braulio Diez
///
/// http://www.tipsdotnet.com
/// ------------------------------





.



Relevant Pages

  • Re: HTTPContext Session and worker thread (Fire and Forget)
    ... To kick of the job you insert record into tblJobs with MessageIn having ... Your aspx page is checking for ActiveJobs counter if it's not 0 then ... not execute job cause it was grabbed by other pooling thread between step 1 ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: HTTPContext Session and worker thread (Fire and Forget)
    ... To kick of the job you insert record into tblJobs with MessageIn having ... Updates Session if job ... not execute job cause it was grabbed by other pooling thread between step 1 ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: HTTPContext Session and worker thread (Fire and Forget)
    ... But in my case, my process would take a minute to execute, and I want to let ... As far as I know Session is thread safe, ... To kick of the job you insert record into tblJobs with MessageIn having ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Will Linux become as vulnerable as MS ??
    ... > beeing vulnerable to viruses. ... > that they know are executable, and execute intentionally. ... >> Linux, each distro is a little different, and even within the distro, ... > Since clicking on a script is easier than typing it's name, ...
    (comp.os.linux.security)
  • Re: [Full-Disclosure] ColdFusion cross-site scripting security vulnerability of an error page
    ... > execute the arbitrary javascript and HTML code which the attacker ... > It is possible to display the contents transmitted from the client ... > cross-site scripting attack can be executed. ... the script will be executed when the script for an attack ...
    (Full-Disclosure)