@@ -21,7 +21,7 @@ public class Alphabet : IAlphabet
21
21
{
22
22
private readonly HanyuPinyinOutputFormat Format = new HanyuPinyinOutputFormat ( ) ;
23
23
private ConcurrentDictionary < string , string [ ] [ ] > PinyinCache ;
24
- private BinaryStorage < ConcurrentDictionary < string , string [ ] [ ] > > _pinyinStorage ;
24
+ private BinaryStorage < Dictionary < string , string [ ] [ ] > > _pinyinStorage ;
25
25
private Settings _settings ;
26
26
27
27
public void Initialize ( [ NotNull ] Settings settings )
@@ -36,8 +36,14 @@ private void InitializePinyinHelpers()
36
36
37
37
Stopwatch . Normal ( "|Wox.Infrastructure.Alphabet.Initialize|Preload pinyin cache" , ( ) =>
38
38
{
39
- _pinyinStorage = new BinaryStorage < ConcurrentDictionary < string , string [ ] [ ] > > ( "Pinyin" ) ;
40
- PinyinCache = _pinyinStorage . TryLoad ( new ConcurrentDictionary < string , string [ ] [ ] > ( ) ) ;
39
+ _pinyinStorage = new BinaryStorage < Dictionary < string , string [ ] [ ] > > ( "Pinyin" ) ;
40
+
41
+ lock ( _pinyinStorage )
42
+ {
43
+ var loaded = _pinyinStorage . TryLoad ( new Dictionary < string , string [ ] [ ] > ( ) ) ;
44
+
45
+ PinyinCache = new ConcurrentDictionary < string , string [ ] [ ] > ( loaded ) ;
46
+ }
41
47
42
48
// force pinyin library static constructor initialize
43
49
PinyinHelper . toHanyuPinyinStringArray ( 'T' , Format ) ;
@@ -79,7 +85,11 @@ public void Save()
79
85
{
80
86
return ;
81
87
}
82
- _pinyinStorage . Save ( PinyinCache ) ;
88
+
89
+ lock ( _pinyinStorage )
90
+ {
91
+ _pinyinStorage . Save ( PinyinCache . ToDictionary ( i => i . Key , i => i . Value ) ) ;
92
+ }
83
93
}
84
94
85
95
private static string [ ] EmptyStringArray = new string [ 0 ] ;
0 commit comments