InputText: Fixed multi-threading issues

This commit is contained in:
spx
2013-03-02 00:29:25 +09:00
parent 76e504d1e5
commit 167123bcf7
3 changed files with 210 additions and 113 deletions

View File

@ -71,17 +71,51 @@ namespace InputText
if (go)
{
ThreadPool.QueueUserWorkItem(ExecuteBangThread, args);
ExecuteBangParam param = new ExecuteBangParam(args);
if (ReadOptions(param)) // Read all options in advance for thread-safety
{
ThreadPool.QueueUserWorkItem(ExecuteBangThread, param);
}
else
{
// No need to continue
lock (this.locker)
{
this.IsExecuteBangRunning = false;
}
}
}
}
internal class ExecuteBangParam
{
internal enum BangType
{
Unknown,
SetVariable,
ExecuteBatch
};
internal Dictionary<string, string> Options;
internal List<string> Commands;
internal string Command;
internal BangType Type;
internal ExecuteBangParam(string args)
{
this.Options = new Dictionary<string, string>();
this.Commands = new List<string>();
this.Command = args.Trim();
this.Type = BangType.Unknown;
}
};
private void ExecuteBangThread(object state)
{
string command = (string)state;
ExecuteBangParam param = (ExecuteBangParam)state;
try
{
ExecuteCommands(command);
ExecuteCommands(param);
}
catch (Exception ex)
{
@ -93,6 +127,11 @@ namespace InputText
this.IsExecuteBangRunning = false;
}
}
internal void Dispose()
{
CloseInputBox();
}
}
#region Plugin
@ -112,6 +151,7 @@ namespace InputText
public unsafe static void Finalize(void* data)
{
uint id = (uint)data;
Measures[id].Dispose();
Measures.Remove(id);
}