program lock bug

This commit is contained in:
AT 2019-11-29 01:38:50 +02:00
parent 09c7955149
commit 132d0631d2
3 changed files with 39 additions and 21 deletions

View File

@ -68,19 +68,25 @@ namespace Wox.Plugin.Program
public List<Result> Query(Query query)
{
Win32[] win32;
UWP.Application[] uwps;
lock (IndexLock)
{
var results1 = _win32s.AsParallel()
.Where(p => p.Enabled)
.Select(p => p.Result(query.Search, _context.API));
var results2 = _uwps.AsParallel()
.Where(p => p.Enabled)
.Select(p => p.Result(query.Search, _context.API));
var result = results1.Concat(results2).Where(r => r.Score > 0).ToList();
return result;
{ // just take the reference inside the lock to eliminate query time issues.
win32 = _win32s;
uwps = _uwps;
}
var results1 = win32.AsParallel()
.Where(p => p.Enabled)
.Select(p => p.Result(query.Search, _context.API));
var results2 = uwps.AsParallel()
.Where(p => p.Enabled)
.Select(p => p.Result(query.Search, _context.API));
var result = results1.Concat(results2).Where(r => r != null && r.Score > 0).ToList();
return result;
}
public void Init(PluginInitContext context)
@ -111,9 +117,9 @@ namespace Wox.Plugin.Program
public static void IndexPrograms()
{
var t1 = Task.Run(()=>IndexWin32Programs());
var t1 = Task.Run(() => IndexWin32Programs());
var t2 = Task.Run(()=>IndexUWPPrograms());
var t2 = Task.Run(() => IndexUWPPrograms());
Task.WaitAll(t1, t2);

View File

@ -276,11 +276,17 @@ namespace Wox.Plugin.Program.Programs
public Result Result(string query, IPublicAPI api)
{
var score = Score(query);
if (score <= 0)
{ // no need to create result if score is 0
return null;
}
var result = new Result
{
SubTitle = Package.Location,
Icon = Logo,
Score = Score(query),
Score = score,
ContextData = this,
Action = e =>
{

View File

@ -45,11 +45,17 @@ namespace Wox.Plugin.Program.Programs
public Result Result(string query, IPublicAPI api)
{
var score = Score(query);
if (score <= 0)
{ // no need to create result if this is zero
return null;
}
var result = new Result
{
SubTitle = FullPath,
IcoPath = IcoPath,
Score = Score(query),
Score = score,
ContextData = this,
Action = e =>
{
@ -193,7 +199,7 @@ namespace Wox.Plugin.Program.Programs
catch (COMException e)
{
// C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\MiracastView.lnk always cause exception
ProgramLogger.LogException($"|Win32|LnkProgram|{path}"+
ProgramLogger.LogException($"|Win32|LnkProgram|{path}" +
"|Error caused likely due to trying to get the description of the program", e);
program.Valid = false;