InputText: Code cleanup

This commit is contained in:
spx 2013-03-06 04:03:43 +09:00
parent 4cf416bd3f
commit 7f8e739ae6
3 changed files with 26 additions and 24 deletions

View File

@ -329,7 +329,7 @@ namespace InputText
public void Abort()
{
this.drBackup = DialogResult.Cancel;
this.drBackup = DialogResult.Abort;
this.Close();
}

View File

@ -72,9 +72,24 @@ namespace InputText
if (go)
{
ExecuteBangParam param = new ExecuteBangParam(args);
if (ReadOptions(param)) // Read all options in advance for thread-safety
if (ReadOptions(param)) // Read all options in main thread for thread-safety
{
ThreadPool.QueueUserWorkItem(ExecuteBangThread, param);
ThreadPool.QueueUserWorkItem(_ =>
{
try
{
ExecuteCommands(param);
}
catch (Exception ex)
{
API.Log(API.LogType.Error, "C# plugin in ExecuteBang(), " + ex.GetType().ToString() + ": " + ex.Message);
}
lock (this.locker)
{
this.IsExecuteBangRunning = false;
}
});
}
else
{
@ -87,7 +102,7 @@ namespace InputText
}
}
internal class ExecuteBangParam
private class ExecuteBangParam
{
internal enum BangType
{
@ -109,28 +124,12 @@ namespace InputText
}
};
private void ExecuteBangThread(object state)
{
ExecuteBangParam param = (ExecuteBangParam)state;
try
{
ExecuteCommands(param);
}
catch (Exception ex)
{
API.Log(API.LogType.Error, "C# plugin in ExecuteBang(), " + ex.GetType().ToString() + ": " + ex.Message);
}
lock (this.locker)
{
this.IsExecuteBangRunning = false;
}
}
private bool _IsFinalizing = false;
internal void Dispose()
{
CloseInputBox();
this._IsFinalizing = true;
FinalizePluginCode();
}
}

View File

@ -264,6 +264,9 @@ namespace InputText
lock (this._InputBoxLocker)
{
if (this._IsFinalizing)
return null;
SkinWindow skin = new SkinWindow(rm);
// Create the form. 'InputBox' is a .NET form with a textbox and two button controls on it.
@ -352,7 +355,7 @@ namespace InputText
return result;
}
private void CloseInputBox()
private void FinalizePluginCode()
{
lock (this._InputBoxLocker)
{