Hi friends,
I want to auto lgo off if user didn't perform any action within 30 min.
Is it possible? iam using .net framwork 2.0.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ifour HirenPosted Nov 3, 2016, 3:25 AM
using System.Windows.Forms;
namespace WindowsApplication1 {
public partial class Form1 : Form, IMessageFilter {
private Timer mTimer;
private int mDialogCount;
public Form1() {
InitializeComponent();
mTimer = new Timer();
mTimer.Interval =1000 * 60 * 30; // for 30 min
mTimer.Tick += LogoutUser;
mTimer.Enabled = true;
Application.AddMessageFilter(this);
}
public bool PreFilterMessage(ref Message m) {
// Monitor message for keyboard and mouse messages
bool active = m.Msg == 0x100 || m.Msg == 0x101; // WM_KEYDOWN/UP
active = active || m.Msg == 0xA0 || m.Msg == 0x200; // WM_(NC)MOUSEMOVE
active = active || m.Msg == 0x10; // WM_CLOSE, in case dialog closes
if (active) {
if (!mTimer.Enabled) label1.Text = "Wakeup";
mTimer.Enabled = false;
mTimer.Start();
}
return false;
}
private void LogoutUser(object sender, EventArgs e) {
// No activity, logout user
if (mDialogCount > 0) return;
mTimer.Enabled = false;
label1.Text = "Time'z up";
}
private void button1_Click(object sender, EventArgs e) {
mDialogCount += 1;
Form frm = new Form2();
frm.ShowDialog();
mDialogCount -= 1;
mTimer.Start();
}
}
}
above code helps you to make it working.
Ali HassoyPosted Nov 15, 2015, 7:04 AM
Sujay SarkarPosted Nov 16, 2014, 9:51 AM
I am Sujay Sarkar from kolkata. Your code is realy wonderful & it's very helpful to me.
Once again thank you very much.
Regards
Sujay Sarkar.
Lebogang NthitePosted Jul 7, 2014, 5:15 AM
Thanks for this code it works pretty well for program. I added few lines of code to make it work (auto log off); I'm just wondering if its gonna be cool with you if I can post this on Code Project since folks are struggling to get this right.
Thanks again.
Sunny DhimanPosted Apr 23, 2012, 9:17 AM
I am not sure but may these steps help you.
Step1) Create window service.
Step2) On login or any activity on you application create a notepad file or make a database entry with actvity time.
Step3) Run window service which continuously check last activity time.
If this time increase more than your time limit then this service restart your window application.So it move you to l login page
Thanks hope it work for you.
John ChagbertPosted Mar 10, 2012, 1:14 AM
Sam HobbsPosted May 7, 2011, 4:19 PM
Sam HobbsPosted May 6, 2011, 7:56 PM
Soft CornerPosted May 6, 2011, 7:11 AM
Don't call me sir , call me shrikant only :)
as per my knowledge, i think we need to do this for each form where u want timeout, bcz we drop the timer control on form.
i will work on this .. once i found solution for this i will share here.
Thanks
Anil KumarPosted May 6, 2011, 7:03 AM
Is there other way to do this? I think the code you suggested, requires to write on each pages.
Soft CornerPosted May 6, 2011, 4:58 AM
you can achieve this using timer control , before that generate Deactivate & Activated event for Window form and implement below in that
private void Form_Activated(object sender, EventArgs e)
{
timer1.Stop();
timer1.Enabled = false;
}
private void Form_Deactivate(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 10000; // interval is in miliseconds .. current interval is for 10 sec
timer1.Start();
}
void timer1_Tick(object sender, EventArgs e)
{
if (timer1.Interval == 10000) // once there window found still deactivated for perticular interval
{
timer1.Stop();
this.Close(); // here you can log off the user & call the new window
}
}