mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
Add activate statistics
This commit is contained in:
@@ -6,6 +6,7 @@ using System.Reflection;
|
||||
using System.Runtime.Serialization.Formatters;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Wox.Infrastructure.Logger;
|
||||
|
||||
namespace Wox.Infrastructure.Storage
|
||||
@@ -18,6 +19,7 @@ namespace Wox.Infrastructure.Storage
|
||||
[Serializable]
|
||||
public abstract class BinaryStorage<T> : BaseStorage<T> where T : class, IStorage, new()
|
||||
{
|
||||
private static object syncObject = new object();
|
||||
protected override string FileSuffix
|
||||
{
|
||||
get { return ".dat"; }
|
||||
@@ -87,25 +89,31 @@ namespace Wox.Infrastructure.Storage
|
||||
|
||||
protected override void SaveInternal()
|
||||
{
|
||||
try
|
||||
ThreadPool.QueueUserWorkItem(o =>
|
||||
{
|
||||
FileStream fileStream = new FileStream(ConfigPath, FileMode.Create);
|
||||
BinaryFormatter binaryFormatter = new BinaryFormatter
|
||||
lock (syncObject)
|
||||
{
|
||||
AssemblyFormat = FormatterAssemblyStyle.Simple
|
||||
};
|
||||
binaryFormatter.Serialize(fileStream, serializedObject);
|
||||
fileStream.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message);
|
||||
try
|
||||
{
|
||||
FileStream fileStream = new FileStream(ConfigPath, FileMode.Create);
|
||||
BinaryFormatter binaryFormatter = new BinaryFormatter
|
||||
{
|
||||
AssemblyFormat = FormatterAssemblyStyle.Simple
|
||||
};
|
||||
binaryFormatter.Serialize(fileStream, serializedObject);
|
||||
fileStream.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
{
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Wox.Infrastructure.Storage
|
||||
@@ -12,6 +13,7 @@ namespace Wox.Infrastructure.Storage
|
||||
/// </summary>
|
||||
public abstract class JsonStrorage<T> : BaseStorage<T> where T : class, IStorage, new()
|
||||
{
|
||||
private static object syncObject = new object();
|
||||
protected override string FileSuffix
|
||||
{
|
||||
get { return ".json"; }
|
||||
@@ -39,8 +41,14 @@ namespace Wox.Infrastructure.Storage
|
||||
|
||||
protected override void SaveInternal()
|
||||
{
|
||||
string json = JsonConvert.SerializeObject(serializedObject, Formatting.Indented);
|
||||
File.WriteAllText(ConfigPath, json);
|
||||
ThreadPool.QueueUserWorkItem(o =>
|
||||
{
|
||||
lock (syncObject)
|
||||
{
|
||||
string json = JsonConvert.SerializeObject(serializedObject, Formatting.Indented);
|
||||
File.WriteAllText(ConfigPath, json);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user