繁体   English   中英

asp.net application_start事件中的问题……它非常非常慢……可能是什么原因?

[英]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.GetString(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){}

}

我认为您可能有两个问题:

  1. Word不支持线程。 简单来说,即使您产生多个线程,word本身一次也只能处理一个文档,有点像单例。 适当的单例实现确实可以在多线程环境中实现这一目标。 此外,考虑时-您只能在任何给定时间编辑一个文档。 当然,您可以有多个Word UI窗口,但是引擎本身(以及您作为用户)一次只能编辑一个文档。

  2. 您的MySQL查询执行时间过长(不太可能)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM