下面是OnStart的代码
protected override void OnStart(string[] args)
{
// TODO: 在此处添加代码以启动服务。
cfg = IndexConfig.LoadXlmDoc(System.IO.Directory.GetParent(Assembly.GetExecutingAssembly().Location) + "/config.xml");
if (cfg == null)
return;
Thread indexerThread = new Thread(new ThreadStart(IndexAllReader));
indexerThread.Name = "Indexer";
indexerThread.IsBackground = true;
indexerThread.Start();
//IndexAllReader();
//WatchDatabaseChange();
//Watcher watcher = new Watcher(cfg);
//watcher.GoAndWatch();
}
下面是IndexAllReader代码:
private void IndexAllReader()
{
System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.Idle;
if (cfg == null)
return;
string connStr = "uid=sa;pwd=mydream54win;Initial Catalog=99scj.com;Data Source=localhost;";
SqlConnection conn = new SqlConnection(connStr);
SqlCommand comm = new SqlCommand("Index_All_Reader", conn);
comm.CommandType = CommandType.StoredProcedure;
conn.Open();
SqlDataReader reader = comm.ExecuteReader();
IndexUpdateReader(reader);
reader.Close();
reader.Dispose();
conn.Close();
conn.Dispose();
}
这里要执行的操作是100W条数据
启动windows服务的时候总是提示错误1053无法启动服务什么的
不知道要怎么样解决
谢谢大家
protected override void OnStart(string[] args)
{
// TODO: 在此处添加代码以启动服务。
cfg = IndexConfig.LoadXlmDoc(System.IO.Directory.GetParent(Assembly.GetExecutingAssembly().Location) + "/config.xml");
if (cfg == null)
return;
Thread indexerThread = new Thread(new ThreadStart(IndexAllReader));
indexerThread.Name = "Indexer";
indexerThread.IsBackground = true;
indexerThread.Start();
//IndexAllReader();
//WatchDatabaseChange();
//Watcher watcher = new Watcher(cfg);
//watcher.GoAndWatch();
}
下面是IndexAllReader代码:
private void IndexAllReader()
{
System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.Idle;
if (cfg == null)
return;
string connStr = "uid=sa;pwd=mydream54win;Initial Catalog=99scj.com;Data Source=localhost;";
SqlConnection conn = new SqlConnection(connStr);
SqlCommand comm = new SqlCommand("Index_All_Reader", conn);
comm.CommandType = CommandType.StoredProcedure;
conn.Open();
SqlDataReader reader = comm.ExecuteReader();
IndexUpdateReader(reader);
reader.Close();
reader.Dispose();
conn.Close();
conn.Dispose();
}
这里要执行的操作是100W条数据
启动windows服务的时候总是提示错误1053无法启动服务什么的
不知道要怎么样解决
谢谢大家
可以指教下吗?
我在onstart里面开了线程啊?
谢谢,恳请再能够详细点指教
如果你开了子线程,那么
cfg = IndexConfig.LoadXlmDoc(System.IO.Directory.GetParent(Assembly.GetExecutingAssembly().Location) + "/config.xml");
这个操作是否正常呢启动失败,肯定是在OnStart出现异常,你自己看看程序是否有Exception没进行捕获
cfg = IndexConfig.LoadXlmDoc(System.IO.Directory.GetParent(Assembly.GetExecutingAssembly().Location) + "/config.xml");
这话没有任何问题
启动服务的时候提示:服务没有及时响应启动或控制请求。
如果我只在private void IndexAllReader()的存储过程返回小量数据如100条记录则能够正常启动,也能够正常执行相应的代码
但是private void IndexAllReader()这个存储过程我返回100W条记录则无法启动,而且在任务管理器里面能够看到这个服务站用的cpu是100%
虽然没有启动成功,但是这个服务却能够正常的执行操作
为什么cpu站用100%呢?我的机器是512M内存,2.66G的cpu
为什么不能够正常启动呢?
应该怎么样解决呢?
IndexUpdateReader,這個怎麽寫的?
感覺是這個裏面循環的問題.
private int IndexUpdateReader(SqlDataReader reader)
{
int i=0;
while(read.Read())
{
i++;
}
return i;
}
应该怎么做呢?
谢谢Knight94(愚翁)
{
int i=0;
while(read.Read())
{
i++;
Thread.Sleep( 10 );//Sleep a little
}
return i;
}
郁闷
干脆请你贴下代码OK?
谢谢
在数据库方面,建议用DataAdapter+DataSet来操作,效率会慢一些,但是连接不是长期占有。
用datatable也是一样的结果啊
郁闷
看来数据不能够取多啊