开发者

problem in asp.net application_start event...its very very slow...what could be the reason?

 void Application_Start(object sender, EventArgs e)
{
    Thread thread = new Thread(new ThreadStart(createIndex));
    thread.Start();
}
void createIndex()
{
    string constring = "server=localhost;port=3306;database=hr;uid=root;password=root" ;   
    String luceneIndexDirectory = @"C:\Index";

    try 
    {
       SimpleAnalyzer analyzer = new SimpleAnalyzer();
       Directory directory = new SimpleFSDirectory(new File(luceneIndexDirectory));
       IndexWriter iwriter = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED);

       MySqlConnection con = new MySqlConnection(constring);
       MySqlCommand com = new MySqlCommand("select emp_id , emp_resume from emp;", con);
       con.Open();
       MySqlDataReader dr = com.ExecuteReader();
       object objPath = null;
       object missing = System.Reflection.Missing.Value;
       object objTrue = true;
       object objFalse = false;
       Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
       while (dr.Read())
       {
           objPath = Server.MapPath("~") + @"\Cnd_Resume\" + dr.GetString(1);
           if(System.IO.File.Exists(Convert.ToString(objPath)))
           {
               Microsoft.Office.Interop.Word.Document d = wordApp.Documents.Open(ref objPath, ref objFalse, ref objTrue, 
                   ref objFalse, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                   ref objFalse, ref missing, ref missing, ref missing, ref missing);

               Document doc = new Document(); 

               doc.add(new Field("id", dr.Ge开发者_开发技巧tString(0) , Field.Store.YES , Field.Index.NOT_ANALYZED ));

               doc.add(new Field("name", dr.GetString(1), Field.Store.YES, Field.Index.NOT_ANALYZED));

               doc.add(new Field("contents", d.Content.Text, Field.Store.NO, Field.Index.ANALYZED));

               d.Close(ref missing, ref missing, ref missing);

               iwriter.addDocument(doc); 
           }
       }

       iwriter.optimize(); 
       iwriter.close(); 
    } 
    catch (Exception ex){}

}


I think you may have two problems:

  1. Word is not thread aware. In simple terms, even though you spawn multiple threads, word itself only processes one document at a time, kind of like a singleton. A proper singleton implementation does achieve this in a multi-threaded environment. Moreover, when you think about it - you can only edit one document at any given time. Sure, you can have multiple Word UI windows, but the engine itself (and you as a user) can only edit one document at a time.

  2. Your MySQL query is taking too long to execute (unlikely).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜