Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7977511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:13:16+00:00 2026-06-04T09:13:16+00:00

i have a function having a loop which sleeps for 6 second at the

  • 0

i have a function having a loop which sleeps for 6 second at the end of each loop

Thread.Sleep(TimeSpan.FromSeconds(6));
this loops 10 times ie the function runs for 60 seconds, each time takin a pause for 6 seconds.

i have authentication test at starting of loop

 if (!HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    return null;
                }

so each time it firsts authenticate then run and wait for 6 seconds.

This is my function:

while (counter < 10)

            {
                if (!HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    return null;
                }

                // doing stuff

                Thread.Sleep(TimeSpan.FromSeconds(6));
                counter++;
            }

now the user logs out in meantime (say in 15th second) . i use ajax to logout and hence dont want to redirect my page. even after logout IsAuthenticated is always true for all 10 loops and is false only when this function is re-executed

for logout i use:

FormsAuthentication.SignOut();
Session.Abandon();
Response.Cookies.Remove(FormsAuthentication.FormsCookieName);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
HttpCookie cookie = HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName];
                if (cookie != null)
                {
                    cookie.Expires = DateTime.Now.AddDays(-1);
                    Response.Cookies.Add(cookie);
                }

but still its true..
i want to stop execution of my thread as soon as user logs out

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:13:18+00:00Added an answer on June 4, 2026 at 9:13 am

    This is happened because the IsAuthenticated have an internal cache because is too much time-expensive to make this authentication again and again. So inside your loop and with out leaving the page, the IsAuthenticated is not change.

    From the other hand, what is the meaning of this ? in a loop a user can see the first 4 thinks, and then can not see the rest because is no more authenticated ? No sense.

    What you can do how ever is to check some other parameter if you like to check if the user have been leave and left the page.

    This is the code that show this internal cache.

    public virtual bool IsAuthenticated
    {
        get
        {
            if (this.m_isAuthenticated == -1)
            {
                WindowsPrincipal principal = new WindowsPrincipal(this);
                SecurityIdentifier sid = new SecurityIdentifier(IdentifierAuthority.NTAuthority, new int[] { 11 });
                this.m_isAuthenticated = principal.IsInRole(sid) ? 1 : 0;
            }
            return (this.m_isAuthenticated == 1);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a classes which have function to make random text and captcha
Im having some trouble writing a getstring function, this is what I have so
I'm attempting to write a function which starts a thread for each contact and
i have a function which retrieves values from a webservice , then loops through
I have a peace of precedural code which is executed in a loop. This
I have a function that generates normal random number matrix having normal distribution using
I have function some_func_1 which will create an object of type some_type and will
Originally, I was having some issues getting this code to function, but after a
I have made an each statement which iterates through each class item found. At
I have an application which is used for data analysis and I'm having a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.