fixing embedding Python multithread problems

This commit is contained in:
qianlifeng
2013-12-25 19:26:58 +08:00
parent 94cd2c0599
commit db18b0f8e2
5 changed files with 33 additions and 26 deletions

View File

@@ -1,7 +1,6 @@
<Window x:Class="WinAlfred.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:winAlfred="clr-namespace:WinAlfred"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:winAlfred="clr-namespace:WinAlfred"
Title="WinAlfred" Height="80" Width="525"
Background="#ebebeb"
Topmost="True"

View File

@@ -1,12 +1,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using WinAlfred.Plugin;
namespace WinAlfred.PluginLoader
{
public class PythonPluginLoader : BasePluginLoader
{
public override List<PluginPair> LoadPlugin()
{
List<PluginPair> plugins = new List<PluginPair>();
@@ -21,9 +21,12 @@ namespace WinAlfred.PluginLoader
};
plugins.Add(pair);
}
foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin))
{
new Thread(plugin.Init).Start();
}
return plugins;
}
}
}

View File

@@ -12,6 +12,8 @@ namespace WinAlfred.PluginLoader
[DllImport("PyWinAlfred.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
private extern static IntPtr ExecPython(string directory, string file, string query);
[DllImport("PyWinAlfred.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
private extern static void InitPythonEnv();
public PythonPluginWrapper(PluginMetadata metadata)
{
@@ -27,7 +29,7 @@ namespace WinAlfred.PluginLoader
public void Init()
{
InitPythonEnv();
}
}
}