Click here to Skip to main content
15,895,011 members
Articles / Programming Languages / C#

How to check for user inactivity with and without platform invokes in C#

Rate me:
Please Sign up or sign in to vote.
4.87/5 (67 votes)
22 Dec 200414 min read 300.2K   7.4K   179  
Within the last month, two fellow programmers asked how to implement a timeout after a certain interval of inactivity. This article features four and a half ways of doing this.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace TestApplication
{
	/// <summary>
	/// Zusammenfassung f�r SomeOtherForm.
	/// </summary>
	public class SomeOtherForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox MyTextBox;
		/// <summary>
		/// Erforderliche Designervariable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public SomeOtherForm()
		{
			//
			// Erforderlich f�r die Windows Form-Designerunterst�tzung
			//
			InitializeComponent();

			//
			// TODO: F�gen Sie den Konstruktorcode nach dem Aufruf von InitializeComponent hinzu
			//
		}

		/// <summary>
		/// Die verwendeten Ressourcen bereinigen.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Vom Windows Form-Designer generierter Code
		/// <summary>
		/// Erforderliche Methode f�r die Designerunterst�tzung. 
		/// Der Inhalt der Methode darf nicht mit dem Code-Editor ge�ndert werden.
		/// </summary>
		private void InitializeComponent()
		{
			this.MyTextBox = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// MyTextBox
			// 
			this.MyTextBox.Location = new System.Drawing.Point(0, 0);
			this.MyTextBox.Multiline = true;
			this.MyTextBox.Name = "MyTextBox";
			this.MyTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
			this.MyTextBox.Size = new System.Drawing.Size(288, 272);
			this.MyTextBox.TabIndex = 0;
			this.MyTextBox.Text = "";
			// 
			// SomeOtherForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 273);
			this.Controls.Add(this.MyTextBox);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.Name = "SomeOtherForm";
			this.Text = "SomeOtherForm";
			this.ResumeLayout(false);

		}
		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions