Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Help! implementing user session timeout in winform c#2.0

Help! implementing user session timeout in winform c#2.0

Scheduled Pinned Locked Moved C#
csharphelpcareer
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    highjo
    wrote on last edited by
    #1

    Hello fellas! i'm trying to built an implementation of user session which timeout after a certain pediod. I have a class usersession which does the job.    <pre>using System.Timers; public class usersession {       private static bool sessionalive;       private static Timer usertimer;       public static bool SessionAlive       {             get { return sessionalive; }             set { sessionalive = value; }       }       public static void   BeginTimer()       {             try             {                SessionAlive = true;                   //usertimer.Start();                usertimer = new Timer(int.Parse(ConfigurationManager.AppSettings["sessiontime"].ToString()));                   usertimer.Enabled = true;                usertimer.AutoReset = false;                  usertimer.Elapsed += new ElapsedEventHandler(DisposeSession);             }             catch (Exception ex)             {                   return;             }       }       private static void   DisposeSession(object source, ElapsedEventArgs e)       {             try             {                   SessionAlive = false;             }             catch (System.Exception ex)             {                   return;     &nbs

    N 1 Reply Last reply
    0
    • H highjo

      Hello fellas! i'm trying to built an implementation of user session which timeout after a certain pediod. I have a class usersession which does the job.    <pre>using System.Timers; public class usersession {       private static bool sessionalive;       private static Timer usertimer;       public static bool SessionAlive       {             get { return sessionalive; }             set { sessionalive = value; }       }       public static void   BeginTimer()       {             try             {                SessionAlive = true;                   //usertimer.Start();                usertimer = new Timer(int.Parse(ConfigurationManager.AppSettings["sessiontime"].ToString()));                   usertimer.Enabled = true;                usertimer.AutoReset = false;                  usertimer.Elapsed += new ElapsedEventHandler(DisposeSession);             }             catch (Exception ex)             {                   return;             }       }       private static void   DisposeSession(object source, ElapsedEventArgs e)       {             try             {                   SessionAlive = false;             }             catch (System.Exception ex)             {                   return;     &nbs

      N Offline
      N Offline
      Noctris
      wrote on last edited by
      #2

      Hi there, Although your idea is not bad, i find it a rather strange way of doing an expired session... what i would do ( although i am no coding god either so feel free to correct me) For example you want your session to be valid for 15 Minutes: You simply make a Session variable like: session.Item("expirationtime") = DateTime.Now().AddMinutes(15) then, on every call you make that is < session.Item("expirationtime") , you set this again

      if(session.item("expirationtime") < DateTime.Now())
      {
      // redirect the user back to the login page

      }

      Seems a hell of a lot simpler and has better performance then spinning of threads to keep timers ticking.. (500 visitors logged in means 500 threads running a timer)

      Do Or Don't, there is no "try catch ex as exception end try"

      H 1 Reply Last reply
      0
      • N Noctris

        Hi there, Although your idea is not bad, i find it a rather strange way of doing an expired session... what i would do ( although i am no coding god either so feel free to correct me) For example you want your session to be valid for 15 Minutes: You simply make a Session variable like: session.Item("expirationtime") = DateTime.Now().AddMinutes(15) then, on every call you make that is < session.Item("expirationtime") , you set this again

        if(session.item("expirationtime") < DateTime.Now())
        {
        // redirect the user back to the login page

        }

        Seems a hell of a lot simpler and has better performance then spinning of threads to keep timers ticking.. (500 visitors logged in means 500 threads running a timer)

        Do Or Don't, there is no "try catch ex as exception end try"

        H Offline
        H Offline
        highjo
        wrote on last edited by
        #3

        hello thanks for the reply and sorry for the late response.i didn't check my mail lately and thought(sorry :)) this subject doen't interest anybody.I'm not sure i understand what you are trying to explain but i have a good news.My same codes is working silly enough from me i put the check.stop(); after calling the loginform.so i did call it before and reset the winforms.forms.timers object on formclosing too.i did some tweak to it.that part was changed to if (!usersession.SessionAlive) { check.Stop(); if(logininstance == null) logininstance = new LoginForm(); logininstance.ShowDialog(); } thanks a lot! ;)

        eager to learn

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups