InputText: Fixed several issues

- Fixed lots of handle leak caused by Threading. Now uses ThreadPool instead of Thread. This change may fix IME issue that cannot input character like Japanese for instance.
- Commented out some non-used part.
- Removed ref keyword from ScanAndReplace().
This commit is contained in:
spx 2013-02-27 11:42:08 +09:00
parent 533d53e446
commit 71601d7564
4 changed files with 122 additions and 160 deletions

View File

@ -2,6 +2,6 @@
using System.Runtime.CompilerServices;
[assembly: AssemblyCopyright("© 2010 - Peter Souza IV")]
[assembly: AssemblyVersion("1.4.0.0")]
[assembly: AssemblyVersion("1.6.0.0")]
[assembly: AssemblyInformationalVersion(Rainmeter.Version.Informational)]
[assembly: AssemblyProduct("Rainmeter")]

View File

@ -18,7 +18,7 @@ namespace InputText
"Peter Souza IV",
// Version
1.05,
1.06,
// E-mail
"psouza4@gmail.com",
@ -125,13 +125,13 @@ namespace InputText
/// </summary>
/// <param name="id">The unique instance ID of this request.</param>
/// <returns>Current value for this meter.</returns>
[DllExport]
public static double Update2(UInt32 id)
{
// Do not modify this member (although you can comment it out). Instead, update
// your code in 'PluginCode.cs'.
return new YourPlugin().Update2(Plugin, id);
}
//[DllExport]
//public static double Update2(UInt32 id)
//{
// // Do not modify this member (although you can comment it out). Instead, update
// // your code in 'PluginCode.cs'.
// return new YourPlugin().Update2(Plugin, id);
//}
/// <summary>
/// Rainmeter's request for text data from the plugin.

View File

@ -19,10 +19,10 @@ namespace InputText
return 0;
}
public double Update2(Rainmeter.Settings.InstanceSettings Instance)
{
return 0.0;
}
//public double Update2(Rainmeter.Settings.InstanceSettings Instance)
//{
// return 0.0;
//}
public string GetString(Rainmeter.Settings.InstanceSettings Instance)
{
@ -176,20 +176,20 @@ namespace InputText
// used. For example:
//
// DefaultValue="hello there, how are you"
sLine = ScanAndReplace(sLine, "DefaultValue", ref Overrides);
sLine = ScanAndReplace(sLine, "X", ref Overrides);
sLine = ScanAndReplace(sLine, "Y", ref Overrides);
sLine = ScanAndReplace(sLine, "W", ref Overrides);
sLine = ScanAndReplace(sLine, "H", ref Overrides);
sLine = ScanAndReplace(sLine, "StringStyle", ref Overrides);
sLine = ScanAndReplace(sLine, "StringAlign", ref Overrides);
sLine = ScanAndReplace(sLine, "FocusDismiss", ref Overrides);
sLine = ScanAndReplace(sLine, "FontColor", ref Overrides);
sLine = ScanAndReplace(sLine, "FontFace", ref Overrides);
sLine = ScanAndReplace(sLine, "SolidColor", ref Overrides);
sLine = ScanAndReplace(sLine, "Password", ref Overrides);
sLine = ScanAndReplace(sLine, "FontSize", ref Overrides);
sLine = ScanAndReplace(sLine, "TopMost", ref Overrides);
sLine = ScanAndReplace(sLine, "DefaultValue", Overrides);
sLine = ScanAndReplace(sLine, "X", Overrides);
sLine = ScanAndReplace(sLine, "Y", Overrides);
sLine = ScanAndReplace(sLine, "W", Overrides);
sLine = ScanAndReplace(sLine, "H", Overrides);
sLine = ScanAndReplace(sLine, "StringStyle", Overrides);
sLine = ScanAndReplace(sLine, "StringAlign", Overrides);
sLine = ScanAndReplace(sLine, "FocusDismiss", Overrides);
sLine = ScanAndReplace(sLine, "FontColor", Overrides);
sLine = ScanAndReplace(sLine, "FontFace", Overrides);
sLine = ScanAndReplace(sLine, "SolidColor", Overrides);
sLine = ScanAndReplace(sLine, "Password", Overrides);
sLine = ScanAndReplace(sLine, "FontSize", Overrides);
sLine = ScanAndReplace(sLine, "TopMost", Overrides);
#endregion
// Get user input
@ -352,7 +352,6 @@ namespace InputText
{
input.ShowDialog(new WindowWrapper(Rainmeter.GetConfigWindow(Instance)));
}
if (input.drBackup != System.Windows.Forms.DialogResult.None)
{
@ -454,7 +453,7 @@ namespace InputText
}
#endregion
#region ScanAndReplace() -- searches for a tag and its value, adding it to overrides if found, and then removing it from the input line
private string ScanAndReplace(string sLine, string sTagName, ref Dictionary<string, string> Overrides)
private string ScanAndReplace(string sLine, string sTagName, Dictionary<string, string> Overrides)
{
if (FindTag(sLine, sTagName))
{

View File

@ -583,104 +583,94 @@ namespace InputText
public UInt32 Update(Rainmeter.Settings Plugin, UInt32 id)
{
bool bAlreadyRunning = (bool)Plugin.Instances[id].GetTempValue("__RMT_U_AlreadyRunning", false);
if (!bAlreadyRunning)
{
UpdateThread thread_details = new UpdateThread(Plugin.Instances[id]);
Thread thread = new Thread(new ThreadStart(thread_details.Go));
thread.Start();
}
//bool bAlreadyRunning = (bool)Plugin.Instances[id].GetTempValue("__RMT_U_AlreadyRunning", false);
//if (!bAlreadyRunning)
//{
// Plugin.Instances[id].SetTempValue("__RMT_U_AlreadyRunning", true);
try
{
return (UInt32)Plugin.Instances[id].GetTempValue("__RMT_U_LastValue", 0);
}
catch
// ThreadPool.QueueUserWorkItem(_instance =>
// {
// Rainmeter.Settings.InstanceSettings Instance = (Rainmeter.Settings.InstanceSettings)_instance;
// try
// {
// Instance.SetTempValue("__RMT_U_LastValue", new PluginCode().Update(Instance));
// }
// catch (Exception ex)
// {
// Rainmeter.Log(Rainmeter.LogLevel.Error, "C# plugin in Update(), " + ex.GetType().ToString() + ": " + ex.Message);
// }
// Instance.SetTempValue("__RMT_U_AlreadyRunning", false);
// }, Plugin.Instances[id]);
//}
//try
//{
// return (UInt32)Plugin.Instances[id].GetTempValue("__RMT_U_LastValue", 0);
//}
//catch
{
return 0;
}
}
private class UpdateThread
{
private Rainmeter.Settings.InstanceSettings Instance = null;
//public double Update2(Rainmeter.Settings Plugin, UInt32 id)
//{
// bool bAlreadyRunning = (bool)Plugin.Instances[id].GetTempValue("__RMT_U2_AlreadyRunning", false);
// if (!bAlreadyRunning)
// {
// Plugin.Instances[id].SetTempValue("__RMT_U2_AlreadyRunning", true);
public UpdateThread(Rainmeter.Settings.InstanceSettings _Instance)
{
this.Instance = _Instance;
}
// ThreadPool.QueueUserWorkItem(_instance =>
// {
// Rainmeter.Settings.InstanceSettings Instance = (Rainmeter.Settings.InstanceSettings)_instance;
public void Go()
{
this.Instance.SetTempValue("__RMT_U_AlreadyRunning", true);
// try
// {
// Instance.SetTempValue("__RMT_U2_LastValue", new PluginCode().Update2(Instance));
// }
// catch (Exception ex)
// {
// Rainmeter.Log(Rainmeter.LogLevel.Error, "C# plugin in Update2(), " + ex.GetType().ToString() + ": " + ex.Message);
// }
try
{
this.Instance.SetTempValue("__RMT_U_LastValue", new PluginCode().Update(this.Instance));
}
catch (Exception ex)
{
Rainmeter.Log(Rainmeter.LogLevel.Error, "C# plugin in GetString(), " + ex.GetType().ToString() + ": " + ex.Message);
}
// Instance.SetTempValue("__RMT_U2_AlreadyRunning", false);
// }, Plugin.Instances[id]);
// }
this.Instance.SetTempValue("__RMT_U_AlreadyRunning", false);
}
}
public double Update2(Rainmeter.Settings Plugin, UInt32 id)
{
bool bAlreadyRunning = (bool)Plugin.Instances[id].GetTempValue("__RMT_U2_AlreadyRunning", false);
if (!bAlreadyRunning)
{
Update2Thread thread_details = new Update2Thread(Plugin.Instances[id]);
Thread thread = new Thread(new ThreadStart(thread_details.Go));
thread.Start();
}
try
{
return (double)Plugin.Instances[id].GetTempValue("__RMT_U2_LastValue", 0.0);
}
catch
{
return 0.0;
}
}
private class Update2Thread
{
private Rainmeter.Settings.InstanceSettings Instance = null;
public Update2Thread(Rainmeter.Settings.InstanceSettings _Instance)
{
this.Instance = _Instance;
}
public void Go()
{
this.Instance.SetTempValue("__RMT_U2_AlreadyRunning", true);
try
{
this.Instance.SetTempValue("__RMT_U2_LastValue", new PluginCode().Update2(this.Instance));
}
catch (Exception ex)
{
Rainmeter.Log(Rainmeter.LogLevel.Error, "C# plugin in GetString(), " + ex.GetType().ToString() + ": " + ex.Message);
}
this.Instance.SetTempValue("__RMT_U2_AlreadyRunning", false);
}
}
// try
// {
// return (double)Plugin.Instances[id].GetTempValue("__RMT_U2_LastValue", 0.0);
// }
// catch
// {
// return 0.0;
// }
//}
public string GetString(Rainmeter.Settings Plugin, UInt32 id)
{
bool bAlreadyRunning = (bool)Plugin.Instances[id].GetTempValue("__RMT_GS_AlreadyRunning", false);
if (!bAlreadyRunning)
{
GetStringThread thread_details = new GetStringThread(Plugin.Instances[id]);
Thread thread = new Thread(new ThreadStart(thread_details.Go));
thread.Start();
Plugin.Instances[id].SetTempValue("__RMT_GS_AlreadyRunning", true);
ThreadPool.QueueUserWorkItem(_instance =>
{
Rainmeter.Settings.InstanceSettings Instance = (Rainmeter.Settings.InstanceSettings)_instance;
try
{
Instance.SetTempValue("__RMT_GS_LastValue", new PluginCode().GetString(Instance));
}
catch (Exception ex)
{
Rainmeter.Log(Rainmeter.LogLevel.Error, "C# plugin in GetString(), " + ex.GetType().ToString() + ": " + ex.Message);
}
Instance.SetTempValue("__RMT_GS_AlreadyRunning", false);
}, Plugin.Instances[id]);
}
try
@ -693,70 +683,43 @@ namespace InputText
}
}
private class GetStringThread
{
private Rainmeter.Settings.InstanceSettings Instance = null;
public GetStringThread(Rainmeter.Settings.InstanceSettings _Instance)
{
this.Instance = _Instance;
}
public void Go()
{
this.Instance.SetTempValue("__RMT_GS_AlreadyRunning", true);
try
{
this.Instance.SetTempValue("__RMT_GS_LastValue", new PluginCode().GetString(this.Instance));
}
catch (Exception ex)
{
Rainmeter.Log(Rainmeter.LogLevel.Error, "C# plugin in GetString(), " + ex.GetType().ToString() + ": " + ex.Message);
}
this.Instance.SetTempValue("__RMT_GS_AlreadyRunning", false);
}
}
public void ExecuteBang(Rainmeter.Settings Plugin, UInt32 id, string sArguments)
{
bool bAlreadyRunning = (bool)Plugin.Instances[id].GetTempValue("__RMT_EB_AlreadyRunning", false);
if (!bAlreadyRunning)
{
ExecuteBangThread thread_details = new ExecuteBangThread(Plugin.Instances[id], sArguments);
Thread thread = new Thread(new ThreadStart(thread_details.Go));
thread.Start();
Plugin.Instances[id].SetTempValue("__RMT_EB_AlreadyRunning", true);
ThreadPool.QueueUserWorkItem(_param =>
{
Rainmeter.Settings.InstanceSettings Instance = (Rainmeter.Settings.InstanceSettings)((ExecuteBangParam)_param).Instance;
string Command = (string)((ExecuteBangParam)_param).Command;
try
{
new PluginCode().ExecuteBang(Instance, Command);
}
catch (Exception ex)
{
Rainmeter.Log(Rainmeter.LogLevel.Error, "C# plugin in ExecuteBang(), " + ex.GetType().ToString() + ": " + ex.Message);
}
Instance.SetTempValue("__RMT_EB_AlreadyRunning", false);
}, new ExecuteBangParam(Plugin.Instances[id], sArguments));
}
return;
}
private class ExecuteBangThread
private class ExecuteBangParam
{
private Rainmeter.Settings.InstanceSettings Instance = null;
private string Command = string.Empty;
public Rainmeter.Settings.InstanceSettings Instance = null;
public string Command = string.Empty;
public ExecuteBangThread(Rainmeter.Settings.InstanceSettings _Instance, string _Command)
public ExecuteBangParam(Rainmeter.Settings.InstanceSettings _Instance, string _Command)
{
this.Instance = _Instance;
this.Command = _Command;
}
public void Go()
{
this.Instance.SetTempValue("__RMT_EB_AlreadyRunning", true);
try
{
new PluginCode().ExecuteBang(this.Instance, this.Command);
}
catch (Exception ex)
{
Rainmeter.Log(Rainmeter.LogLevel.Error, "C# plugin in GetString(), " + ex.GetType().ToString() + ": " + ex.Message);
}
this.Instance.SetTempValue("__RMT_EB_AlreadyRunning", false);
}
}
#endregion