防止被logout 方法 (anti lock mouse)
返得工多, 遇得多server, 都總會遇到 行開一陣就被screen lock,
如果有個batch job 行緊,重可能被強行 logout
但我搵極都搵唔到方法reset佢
結果就寫左個program
個program 其實好簡單
定期去移一移隻 mouse
但遇到個問題, 應該幾耐郁一次, 郁幾遠呢 ?
我冇深究這問題, 但幸運地, 佢令到個server唔會auto lock .... :D
有興趣可以自己抄一份
public partial class Form1 : Form
{
private bool isOn = true;
private int WaitSecond = 60;
System.Threading.Thread thread;
public Form1()
{
InitializeComponent();
thread = new System.Threading.Thread(Run);
thread.Start();
textBox1.Text = WaitSecond.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
isOn = !isOn;
button1.Enabled = false;
button1.Text = isOn ? "Running" : "Not Running";
WaitSecond = Convert.ToInt32(textBox1.Text);
if (isOn)
{
thread.Abort();
thread = new System.Threading.Thread(Run);
thread.Start();
}
else
{
thread.Abort();
}
button1.Enabled = true;
}
private void Run()
{
while (true)
{
Cursor.Position = new Point(Cursor.Position.X + 10, Cursor.Position.Y + 10);
System.Threading.Thread.Sleep(WaitSecond * 500);
Cursor.Position = new Point(Cursor.Position.X - 10, Cursor.Position.Y - 10);
System.Threading.Thread.Sleep(WaitSecond * 500);
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
thread.Abort();
}
}

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home