how to do a PAUSE in an codebehind function?

J

Jason Shohet

I want a function to pause, then resume in 30 seconds.
I know it sounds wierd... I have a situation that I need to write a cookie,
but the user does not have rights to drive at the time the asp.net page
loads, and I think this is preventing the cookie from being written. I need
the code to pause, then in 30 seconds write the cookie.....

anyone know if this can be done?
TY
jason shohet
 
P

Patrice

System.Threading.Thread.Current.Sleep (unsure about the exact name but
should be close).

Which drive ? Usually, cookies are handled client side in a location only IE
has to care about. A user is able to choose from several level of security
for cookies (up to no cookies at all in which case you are unlikely able to
to something). AFAIK if you rpovide more information about your usage of
cookies you should be able to work in some of the restrictred levels...

Patrice
 
C

Craig Deelsnyder

Jason said:
I want a function to pause, then resume in 30 seconds.
I know it sounds wierd... I have a situation that I need to write a cookie,
but the user does not have rights to drive at the time the asp.net page
loads, and I think this is preventing the cookie from being written. I need
the code to pause, then in 30 seconds write the cookie.....

anyone know if this can be done?
TY
jason shohet

I believe you can do this by getting a reference to the current thread
for your request and have it sleep:

System.Threading.Thread.Current.Sleep(30 * 1000);

I'm pretty sure that arg is milliseconds, please verify.
 
A

Alex Papadimoulis

Jason,

As the other poster mentioned, cookies to disk by the client web browser.
When they leave the server, they appear simply as a HTTP Header, like this:
Set-Cookie: NAME=VALUE; expires=DATE; path=PATH; domain=DOMAIN_NAME; secure

The browser then decides what to do with that text (if anything). Cookies
are also sent back to the server in the same manner.

Therefore, causing the page to Sleep will do absolutely nothing. Please
provide more specific infomation.
 
J

Jason Shohet

Thanks guys. To answer, this is what is happening. There's a startup
routine that occurs when a user logs on to their machine. That routine
starts a browser (hidden), which will write a cookie onto the user's
machine. Thats what we want to do...

Yesterday we tried it, and the thing would not write the cookie. Our
hypothesis was that at the time the startup routine is opening the browser,
the cookie cannot be written to the HD ( which doesn't occur for another 15
seconds aprox). My thinking was, cookies get written to IE's folder. If
that folder is not accessible for a particular amount of time, I can try
waiting around, then writing the cookie 30 sec later...
 
P

Patrice

Is the script launched under the user identity ? (how it is hidden, non
interactive mode ?)

If IE is able to connect to your page, it 's really unlikely it would be
unable to write cookies because it's startup. IMO it could write actually in
another profile.

Patrice
 
J

Jason Shohet

thanks to you, Patrice etc.
FYI just wanted to say, it seems its:

System.Threading.Thread.Sleep(30*1000)

Note, the 'Current' word is no longer there. There is something called
CurrentThread, but it does not have the Sleep() method :)
 
J

Jason Shohet

Patrice,
I've got another way now to do it, i don't need to do it in the startup
script. It seems that the application variable %COMPUTERNAME% can be used
in the querystring to give me the machinename, when the application is
called. I'm having another issue related to this (I just posted it), but
I'm much closer now to what I want to do and don't have to worry about doing
this in a startup script. TY
 
K

Kevin Spencer

Hi Jason,

Did you understand what you were told about the cookie being in a Response
header? You don't need to open a new browser instance to set a cookie on the
client machine. Just add the cookie in any Page's Response.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
J

Jason Shohet

Well I gather, that after code has executing on the server, the page is
going back to the client. The page has a header, and the cookie is
contained in that http header. Then the browser decides to save it, or
whatever. We use cookies all over the place, writing them, reading them,
normally we don't need to start up a separate browser session. The problem
here is that we wanted a cookie to write the machinename -- AND, we do not
have netbios on the desktops, so we can only get that machine name from an
app variable.
An app variable is available at startup (starting up the computer) that
contains this computer name, and thats the only place we figured we can get
this cookie written -- way before the user has even opened the application.
So we were going to open the app silently (hidden) during startup, write the
cookie, and then close the app.

Then when the user goes into the app later on, the cookie is there and we
can read it. But we found another solution. It turns out though, that we
found that the %COMPUTERNAME% app variable is always avail. on the user's
machine, even after startup, and it can be used in the querystring. So
we're able to call the app like:
http://myapp/default.aspx?computername=%COMPUTERNAME%

And i've got it working this way.... jason shohet






When they leave the server, they appear simply as a HTTP Header, like this:
Set-Cookie: NAME=VALUE; expires=DATE; path=PATH; domain=DOMAIN_NAME; secure

The browser then decides what to do with that text (if anything). Cookies
are also sent back to the server in the same manner.

Therefore, causing the page to Sleep will do absolutely nothing. Please
provide more specific infomation.
 
K

Kevin Spencer

Okay, now try it out on the Internet, on a published site.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top