Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Timeout Functions

, 11 Dec 2008 CPOL
This article explains about executing a function within a time limit. Also includes a helper class which helps to implement timeout functions easily. This article deals with running multiple timeout processes each with time limit.
namespace TimeoutFunctions.Sample
{
    partial class TimeoutFunctionsSample
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing) {
            if (disposing && (components != null)) {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent() {
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.label1 = new System.Windows.Forms.Label();
            this.txtSynchronousProcessTimeout = new System.Windows.Forms.TextBox();
            this.btnStart = new System.Windows.Forms.Button();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.lstResults = new System.Windows.Forms.ListBox();
            this.groupBox3 = new System.Windows.Forms.GroupBox();
            this.txtAsyncProcessTimeout = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.txtNoOfProcesses = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.btnStartAsyncProcesses = new System.Windows.Forms.Button();
            this.groupBox1.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.groupBox3.SuspendLayout();
            this.SuspendLayout();
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.btnStart);
            this.groupBox1.Controls.Add(this.txtSynchronousProcessTimeout);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.Location = new System.Drawing.Point(12, 12);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(302, 62);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Process details";
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(6, 27);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(136, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Timeout interval in seconds";
            // 
            // txtSynchronousProcessTimeout
            // 
            this.txtSynchronousProcessTimeout.Location = new System.Drawing.Point(148, 24);
            this.txtSynchronousProcessTimeout.Name = "txtSynchronousProcessTimeout";
            this.txtSynchronousProcessTimeout.Size = new System.Drawing.Size(55, 20);
            this.txtSynchronousProcessTimeout.TabIndex = 1;
            this.txtSynchronousProcessTimeout.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            // 
            // btnStart
            // 
            this.btnStart.Location = new System.Drawing.Point(209, 22);
            this.btnStart.Name = "btnStart";
            this.btnStart.Size = new System.Drawing.Size(75, 23);
            this.btnStart.TabIndex = 2;
            this.btnStart.Text = "Start";
            this.btnStart.UseVisualStyleBackColor = true;
            this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
            // 
            // groupBox2
            // 
            this.groupBox2.Controls.Add(this.lstResults);
            this.groupBox2.Location = new System.Drawing.Point(12, 205);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(302, 224);
            this.groupBox2.TabIndex = 1;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "Output window";
            // 
            // lstResults
            // 
            this.lstResults.FormattingEnabled = true;
            this.lstResults.Location = new System.Drawing.Point(6, 19);
            this.lstResults.Name = "lstResults";
            this.lstResults.Size = new System.Drawing.Size(290, 199);
            this.lstResults.TabIndex = 0;
            // 
            // groupBox3
            // 
            this.groupBox3.Controls.Add(this.btnStartAsyncProcesses);
            this.groupBox3.Controls.Add(this.txtNoOfProcesses);
            this.groupBox3.Controls.Add(this.label3);
            this.groupBox3.Controls.Add(this.txtAsyncProcessTimeout);
            this.groupBox3.Controls.Add(this.label2);
            this.groupBox3.Location = new System.Drawing.Point(12, 80);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new System.Drawing.Size(302, 119);
            this.groupBox3.TabIndex = 2;
            this.groupBox3.TabStop = false;
            this.groupBox3.Text = "Asynchronous process";
            // 
            // txtAsyncProcessTimeout
            // 
            this.txtAsyncProcessTimeout.Location = new System.Drawing.Point(148, 30);
            this.txtAsyncProcessTimeout.Name = "txtAsyncProcessTimeout";
            this.txtAsyncProcessTimeout.Size = new System.Drawing.Size(55, 20);
            this.txtAsyncProcessTimeout.TabIndex = 3;
            this.txtAsyncProcessTimeout.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(6, 33);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(136, 13);
            this.label2.TabIndex = 2;
            this.label2.Text = "Timeout interval in seconds";
            // 
            // txtNoOfProcesses
            // 
            this.txtNoOfProcesses.Location = new System.Drawing.Point(148, 60);
            this.txtNoOfProcesses.Name = "txtNoOfProcesses";
            this.txtNoOfProcesses.Size = new System.Drawing.Size(55, 20);
            this.txtNoOfProcesses.TabIndex = 5;
            this.txtNoOfProcesses.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(6, 63);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(107, 13);
            this.label3.TabIndex = 4;
            this.label3.Text = "Number of processes";
            // 
            // btnStartAsyncProcesses
            // 
            this.btnStartAsyncProcesses.Location = new System.Drawing.Point(209, 58);
            this.btnStartAsyncProcesses.Name = "btnStartAsyncProcesses";
            this.btnStartAsyncProcesses.Size = new System.Drawing.Size(75, 23);
            this.btnStartAsyncProcesses.TabIndex = 6;
            this.btnStartAsyncProcesses.Text = "Start";
            this.btnStartAsyncProcesses.UseVisualStyleBackColor = true;
            this.btnStartAsyncProcesses.Click += new System.EventHandler(this.btnStartAsyncProcesses_Click);
            // 
            // TimeoutFunctionsSample
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(322, 441);
            this.Controls.Add(this.groupBox3);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.groupBox1);
            this.MaximizeBox = false;
            this.Name = "TimeoutFunctionsSample";
            this.Text = "Timeout Functions Sample";
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.groupBox2.ResumeLayout(false);
            this.groupBox3.ResumeLayout(false);
            this.groupBox3.PerformLayout();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.TextBox txtSynchronousProcessTimeout;
        private System.Windows.Forms.Button btnStart;
        private System.Windows.Forms.GroupBox groupBox2;
        private System.Windows.Forms.ListBox lstResults;
        private System.Windows.Forms.GroupBox groupBox3;
        private System.Windows.Forms.Button btnStartAsyncProcesses;
        private System.Windows.Forms.TextBox txtNoOfProcesses;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.TextBox txtAsyncProcessTimeout;
        private System.Windows.Forms.Label label2;
    }
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

N a v a n e e t h
Software Developer ThoughtWorks
India India
Call me Navaneeth Some years ago--never mind how long precisely, I was doing programs with C and C++. When .NET came, I started with C#,ASP.NET and SQL Server.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141220.1 | Last Updated 11 Dec 2008
Article Copyright 2008 by N a v a n e e t h
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid