Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2057 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
4 changed files with 170 additions and 3 deletions
@ -0,0 +1,74 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
namespace SearchAndReplace |
||||||
|
{ |
||||||
|
partial class AsynchronousWaitDialog : System.Windows.Forms.Form |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Designer variable used to keep track of non-visual components.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null; |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Disposes resources used by the form.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing) |
||||||
|
{ |
||||||
|
if (disposing) { |
||||||
|
if (components != null) { |
||||||
|
components.Dispose(); |
||||||
|
} |
||||||
|
} |
||||||
|
base.Dispose(disposing); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This method is required for Windows Forms designer support.
|
||||||
|
/// Do not change the method contents inside the source code editor. The Forms designer might
|
||||||
|
/// not be able to load this method if it was changed manually.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent() |
||||||
|
{ |
||||||
|
this.label1 = new System.Windows.Forms.Label(); |
||||||
|
this.progressBar1 = new System.Windows.Forms.ProgressBar(); |
||||||
|
this.SuspendLayout(); |
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
this.label1.Location = new System.Drawing.Point(93, 23); |
||||||
|
this.label1.Name = "label1"; |
||||||
|
this.label1.Size = new System.Drawing.Size(100, 23); |
||||||
|
this.label1.TabIndex = 0; |
||||||
|
this.label1.Text = "Please wait..."; |
||||||
|
//
|
||||||
|
// progressBar1
|
||||||
|
//
|
||||||
|
this.progressBar1.Location = new System.Drawing.Point(12, 49); |
||||||
|
this.progressBar1.Name = "progressBar1"; |
||||||
|
this.progressBar1.Size = new System.Drawing.Size(264, 23); |
||||||
|
this.progressBar1.Style = System.Windows.Forms.ProgressBarStyle.Marquee; |
||||||
|
this.progressBar1.TabIndex = 1; |
||||||
|
//
|
||||||
|
// AsynchronousWaitDialog
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); |
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; |
||||||
|
this.ClientSize = new System.Drawing.Size(288, 84); |
||||||
|
this.ControlBox = false; |
||||||
|
this.Controls.Add(this.progressBar1); |
||||||
|
this.Controls.Add(this.label1); |
||||||
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; |
||||||
|
this.Name = "AsynchronousWaitDialog"; |
||||||
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; |
||||||
|
this.Text = "AsynchronousWaitDialog"; |
||||||
|
this.ResumeLayout(false); |
||||||
|
} |
||||||
|
private System.Windows.Forms.ProgressBar progressBar1; |
||||||
|
private System.Windows.Forms.Label label1; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,72 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Drawing; |
||||||
|
using System.Threading; |
||||||
|
using System.Windows.Forms; |
||||||
|
|
||||||
|
namespace SearchAndReplace |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Shows an wait dialog on a separate thread if the action takes longer than 200ms.
|
||||||
|
/// Usage:
|
||||||
|
/// using (AsynchronousWaitDialog.ShowWaitDialog()) {
|
||||||
|
/// long_running_action();
|
||||||
|
/// }
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class AsynchronousWaitDialog |
||||||
|
{ |
||||||
|
class WaitHandle : IDisposable |
||||||
|
{ |
||||||
|
bool disposed; |
||||||
|
AsynchronousWaitDialog dlg; |
||||||
|
|
||||||
|
[STAThread] |
||||||
|
public void Run() |
||||||
|
{ |
||||||
|
Thread.Sleep(500); |
||||||
|
lock (this) { |
||||||
|
if (disposed) |
||||||
|
return; |
||||||
|
dlg = new AsynchronousWaitDialog(); |
||||||
|
dlg.CreateControl(); |
||||||
|
} |
||||||
|
Application.Run(dlg); |
||||||
|
} |
||||||
|
|
||||||
|
public void Dispose() |
||||||
|
{ |
||||||
|
lock (this) { |
||||||
|
disposed = true; |
||||||
|
if (dlg != null) { |
||||||
|
dlg.BeginInvoke(new MethodInvoker(dlg.Close)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static IDisposable ShowWaitDialog() |
||||||
|
{ |
||||||
|
WaitHandle h = new WaitHandle(); |
||||||
|
Thread thread = new Thread(h.Run); |
||||||
|
thread.Name = "AsynchronousWaitDialog thread"; |
||||||
|
thread.Start(); |
||||||
|
|
||||||
|
Thread.Sleep(0); // allow new thread to start
|
||||||
|
return h; |
||||||
|
} |
||||||
|
|
||||||
|
private AsynchronousWaitDialog() |
||||||
|
{ |
||||||
|
//
|
||||||
|
// The InitializeComponent() call is required for Windows Forms designer support.
|
||||||
|
//
|
||||||
|
InitializeComponent(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue