我编写了一个小应用程序,它可以生成单词,然后根据 Microsoft Word 2007 字典验证它们。
当我用 3 个字母长度(我猜有更多字母)对它进行测试时,这对我来说非常有用,但是由于某种原因,当我尝试对希伯来语词典运行它时它停止工作。
有谁知道为什么?如果是,我该如何解决?如果有更好的方法可以做到这一点,如果有人能指出,我会很高兴。
谢谢。
更新:当我说它停止时,我的意思是它停止检查单词。我得到所有单词组合直到最后,但它们没有被检查。
主窗口.xaml
<Window x:Class="AllHebrewWords.CreateDictionary"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="List of words" Height="250" Width="150" Closing="Window_Closing" ResizeMode="CanMinimize">
<Grid>
<ListBox Margin="10,10,10,10" Name="WordsList" />
</Grid>
</Window>
主窗口.xaml.cs
using System.Diagnostics;
using System.Reflection;
using System.Threading;
using Microsoft.Office.Interop.Word;
namespace AllHebrewWords
{
public partial class CreateDictionary : System.Windows.Window
{
private Application app = null;
private _Document doc = null;
private Thread thread = null;
object oMissing = Missing.Value;
public CreateDictionary()
{
InitializeComponent();
app = new Application();
object visible = false;
doc = app.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref visible);
thread = new Thread(SearchThread);
thread.Start();
} // End of function
public void SearchThread()
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
for (char ch = 'א'; ch <= 'ת'; ch++)
{
AddLetter(ch.ToString());
} // End of for
object FileName = "C:/Words";
object FileFormat = WdSaveFormat.wdFormatText;
doc.SaveAs( ref FileName, ref FileFormat, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
stopwatch.Stop();
Dispatcher.Invoke((ThreadStart)delegate() { WordsList.Items.Add("Dictionary ready"); });
Dispatcher.Invoke((ThreadStart)delegate() { WordsList.Items.Add(stopwatch.Elapsed); });
Dispatcher.Invoke((ThreadStart)delegate() { WordsList.ScrollIntoView(WordsList.Items[WordsList.Items.Count - 1]); });
} // End of function
public bool CheckWord(string word)
{
if (app.CheckSpelling(word))
{
doc.Words.Last.InsertAfter(word + '\n');
return true;
}
return false;
} // End of function
public void AddLetter(string word)
{
CheckWord(word);
if (word.Length < 3)
{
char ch = word[word.Length - 1];
for (ch = 'א'; ch <= 'ת'; ch++)
{
word += ch;
AddLetter(word);
word = word.Remove(word.Length - 1);
} // End of for
} // End of if
} // End of function
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
object saveChanges = false;
doc.Close(ref saveChanges, ref oMissing, ref oMissing);
thread.Abort();
app.Quit(ref saveChanges, ref oMissing, ref oMissing);
} // End of function
} // End of class
} // End of namespace