{"id":275,"date":"2008-06-01T14:45:01","date_gmt":"2008-06-01T14:45:01","guid":{"rendered":"http:\/\/dalelane.co.uk\/blog\/?p=275"},"modified":"2008-06-01T19:46:36","modified_gmt":"2008-06-01T19:46:36","slug":"back-at-work-gradually","status":"publish","type":"post","link":"https:\/\/dalelane.co.uk\/blog\/?p=275","title":{"rendered":"Back at work&#8230; gradually"},"content":{"rendered":"<p>Hurrah &#8211; after a <a href=\"http:\/\/dalelane.co.uk\/blog\/?p=266\" target=\"_blank\">two and a half weeks being stuck at home<\/a>, the doc tells me that my back is well enough for me to go back to work tomorrow.  <\/p>\n<p>I&#8217;m not fully recovered &#8211; the estimate for that is still 6 &#8211; 8 weeks, so I&#8217;m been warned to take it easy for a few weeks. In particular, he made it very clear that I must get up and stretch my legs regularly, as prolonged periods sitting could set my recovery back.  <\/p>\n<p><img decoding=\"async\" src=\"http:\/\/dalelane.co.uk\/blog\/post-images\/080601-autolock.gif\" alt=\"screenshot\" hspace=\"5\" vspace=\"5\" align=\"left\"\/>Unfortunately, I know I have a habit of being a bit single-minded (some might say &#8220;obsessive&#8221; \ud83d\ude09 ) while I&#8217;m working, and often lose track of time. So I&#8217;ve thrown together a 35-line program to help make sure I don&#8217;t overdo it. <\/p>\n<p>It will automatically lock my ThinkPad after 40 minutes, resetting the timer each time I unlock the ThinkPad again. <\/p>\n<p><!--more-->It&#8217;s an interesting, if trivial app. The code is below. Hopefully it&#8217;ll help! \ud83d\ude42 <\/p>\n<pre style=\"font-size: 1em; border: thin solid silver; background-color: #eeeeee; padding: 0.8em\">private int countdownmins = MINS_TO_WORK; \r\nprivate const string MSG_PREFIX = \"You need to get up and stretch your legs in \"; \r\n\r\npublic Form1() \r\n{ \r\n  InitializeComponent(); \r\n\r\n  timer1.Interval = ONE_MINUTE; \r\n\r\n  SetDisplay(); \r\n  WTSRegisterSessionNotification(Handle, NOTIFY_FOR_THIS_SESSION); \r\n} \r\n\r\nprivate void SetDisplay() \r\n{ \r\n  label1.Text = MSG_PREFIX + countdownmins + \" minutes\"; \r\n} \r\n\r\nprivate void timer1_Tick(object sender, EventArgs e) \r\n{ \r\n  countdownmins -= 1; \r\n  SetDisplay(); \r\n\r\n  if (countdownmins == 0) \r\n  { \r\n    LockWorkStation(); \r\n  } \r\n} \r\n\r\nprotected override void WndProc(ref Message m) \r\n{ \r\n  if ((m.Msg == WM_WTSSESSION_CHANGE) &#38;&#38; \r\n      (m.WParam.ToInt32() == WTS_SESSION_UNLOCK)) \r\n  { \r\n    countdownmins = MINS_TO_WORK; \r\n    SetDisplay();                 \r\n  } \r\n  base.WndProc(ref m); \r\n} \r\n\r\n\r\nprivate const int MINS_TO_WORK = 40; \r\nprivate const int ONE_MINUTE   = 60000; \r\nprivate const int NOTIFY_FOR_THIS_SESSION = 0; \r\nprivate const int WM_WTSSESSION_CHANGE = 0x2b1; \r\nprivate const int WTS_SESSION_LOCK = 0x7; \r\nprivate const int WTS_SESSION_UNLOCK = 0x8; \r\n\r\n[DllImport(\"user32.dll\")] \r\ninternal static extern bool LockWorkStation(); \r\n[DllImport(\"WtsApi32.dll\", SetLastError = true)] \r\ninternal static extern bool WTSRegisterSessionNotification \r\n            (IntPtr hWnd,  \r\n             [MarshalAs(UnmanagedType.U4)] \r\n             int dwFlags);<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Hurrah &#8211; after a two and a half weeks being stuck at home, the doc tells me that my back is well enough for me to go back to work tomorrow. I&#8217;m not fully recovered &#8211; the estimate for that is still 6 &#8211; 8 weeks, so I&#8217;m been warned to take it easy for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[195,216,217,218],"class_list":["post-275","post","type-post","status-publish","format-standard","hentry","category-code","tag-back","tag-lock","tag-lockworkstation","tag-work"],"_links":{"self":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/275","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=275"}],"version-history":[{"count":0,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/275\/revisions"}],"wp:attachment":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}