mirror of
https://github.com/greenshot/greenshot
synced 2025-08-14 02:37:03 -07:00
Work in progress for the Jira backport. [skip ci]
This commit is contained in:
parent
798ca503a5
commit
a3f3c20d71
12 changed files with 402 additions and 4290 deletions
|
@ -30,8 +30,8 @@ namespace GreenshotPlugin.Controls {
|
|||
/// </summary>
|
||||
public partial class PleaseWaitForm : Form {
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(PleaseWaitForm));
|
||||
private Thread waitFor;
|
||||
private string title;
|
||||
private Thread _waitFor;
|
||||
private string _title;
|
||||
public PleaseWaitForm() {
|
||||
//
|
||||
// The InitializeComponent() call is required for Windows Forms designer support.
|
||||
|
@ -60,7 +60,7 @@ namespace GreenshotPlugin.Controls {
|
|||
/// <param name="text">The text in the form</param>
|
||||
/// <param name="waitDelegate">delegate { with your code }</param>
|
||||
public void ShowAndWait(string title, string text, ThreadStart waitDelegate) {
|
||||
this.title = title;
|
||||
_title = title;
|
||||
Text = title;
|
||||
label_pleasewait.Text = text;
|
||||
cancelButton.Text = Language.GetString("CANCEL");
|
||||
|
@ -72,23 +72,29 @@ namespace GreenshotPlugin.Controls {
|
|||
Exception threadException = null;
|
||||
try {
|
||||
// Wrap the passed delegate in a try/catch which makes it possible to save the exception
|
||||
waitFor = new Thread(new ThreadStart(
|
||||
delegate {
|
||||
try {
|
||||
waitDelegate.Invoke();
|
||||
} catch (Exception ex) {
|
||||
LOG.Error("invoke error:", ex);
|
||||
threadException = ex;
|
||||
}
|
||||
})
|
||||
);
|
||||
waitFor.Name = title;
|
||||
waitFor.IsBackground = true;
|
||||
waitFor.SetApartmentState(ApartmentState.STA);
|
||||
waitFor.Start();
|
||||
_waitFor = new Thread(new ThreadStart(
|
||||
delegate
|
||||
{
|
||||
try
|
||||
{
|
||||
waitDelegate.Invoke();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Error("invoke error:", ex);
|
||||
threadException = ex;
|
||||
}
|
||||
})
|
||||
)
|
||||
{
|
||||
Name = title,
|
||||
IsBackground = true
|
||||
};
|
||||
_waitFor.SetApartmentState(ApartmentState.STA);
|
||||
_waitFor.Start();
|
||||
|
||||
// Wait until finished
|
||||
while (!waitFor.Join(TimeSpan.FromMilliseconds(100))) {
|
||||
while (!_waitFor.Join(TimeSpan.FromMilliseconds(100))) {
|
||||
Application.DoEvents();
|
||||
}
|
||||
LOG.DebugFormat("Finished {0}", title);
|
||||
|
@ -110,9 +116,9 @@ namespace GreenshotPlugin.Controls {
|
|||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
void CancelButtonClick(object sender, EventArgs e) {
|
||||
LOG.DebugFormat("Cancel clicked on {0}", title);
|
||||
LOG.DebugFormat("Cancel clicked on {0}", _title);
|
||||
cancelButton.Enabled = false;
|
||||
waitFor.Abort();
|
||||
_waitFor.Abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue