终止线程 [英] Terminate the thread
问题描述
大家好,
我已经编写了代码来运行一组线程,这些线程可以处理来自sql server的数据.
调用Start之后,我已经调用了join.
但是经过处理后,我仍然能够查看数据库中运行的sql服务器实例.
我应该怎么做才能杀死线程完成并结束sql server实例.
在此先感谢!
问候
Govardhan
Hi All,
I have written code to run a set of threads that works on data from sql server.
After calling Start and i have called the join.
But after processing still i am able to view the sql server instance running in database.
What should i do to kill the threads complete and end the sql server instance too.
thanks in advance!
Regards
Govardhan
推荐答案
正确关闭连接..
1)调用Connection的Close()方法
或
2)使用诸如using(Connection con)
之类的``using''关键字 {...}
或
3)检查AutoClose的实现
http://stackoverflow.com/questions/1275079/ado- net-connection-pooling-and-implications-for-autoclose-true [
close the connection properly..
1) call the Close() method of Connection
or
2) use the ''using'' keyword like using(Connection con)
{ ... }
or
3) check the implecations for AutoClose
http://stackoverflow.com/questions/1275079/ado-net-connection-pooling-and-implications-for-autoclose-true[^]
要杀死线程,您可以调用Thread.Abort 方法如下:
For killing thread you can call the Thread.Abort method like the following:
myThread.Abort();
要关闭SQL连接,您可以调用 SqlConnection.Close 方法,或者用using
块包装代码,如下所示:
For closing the SQL connection you can call the SqlConnection.Close method or, wrap your code with a using
block, like the following:
string connectionString = "Your connection string";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
// ...
}
好吧,如果我理解正确的话,您就不会杀死SQL Server实例.它作为服务用尽了进程,您只需断开与它的连接.
Well, if I understand you correctly, you don''t kill the SQL Server Instance. Its running out of process as a service, you merely disconnect from it.
这篇关于终止线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!