⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 retry.cs

📁 CS导航Logo ,在Logo上显示Loading
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace BufferedUploadWin
{
	/// <summary>
	/// Summary description for Retry.
	/// </summary>
	public class Retry : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label lblError;
		private System.Windows.Forms.Button btnRetry;
		private System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.Label lblRetryIn;
		private System.Windows.Forms.Timer timer1;
		private System.ComponentModel.IContainer components;
		private InitDelegate del;
		private System.Windows.Forms.Label lblNumRetriesLeft;	// the function pointer used when the timer elapses to retry, or the user presses retry
		private int timeOut = 10;	

		public Retry()
		{
			InitializeComponent();
		}

		public delegate void InitDelegate();

		/// <summary>
		/// Initialise the Retry form.
		/// </summary>
		/// <param name="errMessage">What went wrong with the upload</param>
		/// <param name="timeOut">Time in seconds the window will stay open before retrying the operation</param>
		/// <param name="del">The delegate pointing to the method to resume the operation, when the user clicks Retry</param>
		/// <param name="numRetriesLeft">The number of remaining times the app will try to recover.  I'm assuming
		/// it shouldn't try forever :)</param>
		public void Init(string errMessage, int timeOut, int numRetriesLeft, InitDelegate del)
		{
			this.del = del;
			this.lblError.Text = errMessage;
			this.timer1.Start();
			this.timeOut = timeOut;
			this.lblRetryIn.Text = "Retrying in " + timeOut + " seconds";
			this.lblNumRetriesLeft.Text = numRetriesLeft + " retries left.";
		}

		private void timer1_Tick(object sender, System.EventArgs e)
		{
			this.timeOut--;
			this.lblRetryIn.Text = "Retrying in " + timeOut + " seconds.";
			if(this.timeOut <= 0)
				this.btnRetry.PerformClick();
		}

		private void btnRetry_Click(object sender, System.EventArgs e)
		{
			del.BeginInvoke(null, null);
			this.DialogResult = DialogResult.OK;
			this.Close();
		}

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(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.components = new System.ComponentModel.Container();
			this.lblError = new System.Windows.Forms.Label();
			this.btnRetry = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.lblRetryIn = new System.Windows.Forms.Label();
			this.timer1 = new System.Windows.Forms.Timer(this.components);
			this.lblNumRetriesLeft = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// lblError
			// 
			this.lblError.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.lblError.Location = new System.Drawing.Point(16, 8);
			this.lblError.Name = "lblError";
			this.lblError.Size = new System.Drawing.Size(368, 40);
			this.lblError.TabIndex = 0;
			// 
			// btnRetry
			// 
			this.btnRetry.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			this.btnRetry.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnRetry.Location = new System.Drawing.Point(96, 88);
			this.btnRetry.Name = "btnRetry";
			this.btnRetry.TabIndex = 1;
			this.btnRetry.Text = "Retry";
			this.btnRetry.Click += new System.EventHandler(this.btnRetry_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnCancel.Location = new System.Drawing.Point(208, 88);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.TabIndex = 2;
			this.btnCancel.Text = "Cancel";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// lblRetryIn
			// 
			this.lblRetryIn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.lblRetryIn.Location = new System.Drawing.Point(88, 56);
			this.lblRetryIn.Name = "lblRetryIn";
			this.lblRetryIn.Size = new System.Drawing.Size(136, 24);
			this.lblRetryIn.TabIndex = 3;
			this.lblRetryIn.Text = "Rertying in 5 seconds.";
			this.lblRetryIn.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// timer1
			// 
			this.timer1.Enabled = true;
			this.timer1.Interval = 1000;
			this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
			// 
			// lblNumRetriesLeft
			// 
			this.lblNumRetriesLeft.Location = new System.Drawing.Point(232, 56);
			this.lblNumRetriesLeft.Name = "lblNumRetriesLeft";
			this.lblNumRetriesLeft.Size = new System.Drawing.Size(112, 23);
			this.lblNumRetriesLeft.TabIndex = 4;
			this.lblNumRetriesLeft.Text = "5 retries left";
			this.lblNumRetriesLeft.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// Retry
			// 
			this.AcceptButton = this.btnRetry;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.CancelButton = this.btnCancel;
			this.ClientSize = new System.Drawing.Size(392, 118);
			this.Controls.Add(this.lblNumRetriesLeft);
			this.Controls.Add(this.lblRetryIn);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnRetry);
			this.Controls.Add(this.lblError);
			this.Name = "Retry";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "Error";
			this.ResumeLayout(false);

		}
		#endregion

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			this.DialogResult = DialogResult.Cancel;
			this.Close();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -