如何在c#中杀死一个线程? [英] How to kill a thread in c#?

查看:88
本文介绍了如何在c#中杀死一个线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




这就是我想做的事情:


1.启动应用程序。

2.启动在自己的线程中运行的SplashScreen。

3.我正在检查应用程序是否需要更新。

4.如果更新需要我关闭SplashScreen并复制文件。

5.重新启动应用程序。


我的问题发生在第4步。我尝试了一切我知道

关闭SplashScreen,但我似乎无法做到。当

应用程序文件被替换时,它总是说

可执行文件被另一个进程使用。


如果我删除与SplashScreen相关的代码,一切正常工作

罚款。


我尝试使用以下代码调用SplashScreen中的函数:

ms_oThread.Abort();

ms_oThread.Join();

ms_oThread = null;


是不工作。

任何人都知道我怎么能这样做?


谢谢

Hi,

Here''s what I want to do:

1. Start the application.
2. A SplashScreen running in its own thread is started.
3. I''m checking if the application needs an update.
4. If an update is needed I close the SplashScreen and copy the file.
5. Restart the application.

My problem is happening at step 4. I tried everything that I know to
close the SplashScreen, but I seems to be unable to do it. When the
application file is being replace it''s always saying that the
executable is used by another process.

If I remove the code related to the SplashScreen everything is working
fine.

I tried to call a function in the SplashScreen with this code:
ms_oThread.Abort();
ms_oThread.Join();
ms_oThread = null;

Was not working.
Anyone have any idea how I could be able to do that?

Thanks

推荐答案

bie2,


如果你有一个应用程序检查自己的更新,你将需要一个

单独的程序这样做。该程序将加载启动画面,

然后替换主应用程序可执行文件,如果它发现它需要

更新。否则,它只运行主应用程序。由于二进制文件是加载到CLR中的
,因此您无法删除该文件。


另外,您是否已查看Microsoft的更新管理块? ?

或ClickOnce(如果你可以等待,可以使用.NET 2.0)。这两个

都解决了这个问题,并且可能会减少您需要的代码数量

写。


希望这个帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" bie2" < TA ****** @ adelphia.net>在消息中写道

news:11 ********************** @ f14g2000cwb.googlegr oups.com ...
bie2,

If you have an application checking itself for updates, you will need a
separate program that does it. This program will load the splash screen,
and then replace the main application executable if it finds it needs an
update. Otherwise, it just runs the main application. Since the binary is
loaded into the CLR, you can''t delete the file.

Also, have you looked into the update management block from Microsoft?
Or ClickOnce (due out with .NET 2.0, if you can wait for it). Both of these
address this issue, and would probably reduce the amount of code you have to
write.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"bie2" <ta******@adelphia.net> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...


这就是我想做的事情:

1.启动应用程序。
2.自己运行的SplashScreen线程已启动。
3.我正在检查应用程序是否需要更新。
4.如果需要更新,请关闭SplashScreen并复制文件。
5.重新启动应用程序。

我的问题发生在第4步。我尝试了所有我知道的关闭SplashScreen,但我似乎无法做到。当
应用程序文件被替换时,它总是说
可执行文件被另一个进程使用。

如果我删除与SplashScreen相关的代码,一切正常
很好。

我试着使用以下代码调用SplashScreen中的函数:
ms_oThread.Abort();
ms_oThread.Join();
ms_oThread = null;

不工作。
任何人都知道我怎么能这样做?

谢谢
Hi,

Here''s what I want to do:

1. Start the application.
2. A SplashScreen running in its own thread is started.
3. I''m checking if the application needs an update.
4. If an update is needed I close the SplashScreen and copy the file.
5. Restart the application.

My problem is happening at step 4. I tried everything that I know to
close the SplashScreen, but I seems to be unable to do it. When the
application file is being replace it''s always saying that the
executable is used by another process.

If I remove the code related to the SplashScreen everything is working
fine.

I tried to call a function in the SplashScreen with this code:
ms_oThread.Abort();
ms_oThread.Join();
ms_oThread = null;

Was not working.
Anyone have any idea how I could be able to do that?

Thanks


尼克,

您有.NET Framework 2.0,VS.NET 2005和SQL 2005时的信息吗? b $ b将被释放?我们计划将它用于我们的下一代

应用程序。谢谢!


John

" Nicholas Paldino [.NET / C#MVP]" < mv*@spam.guard.caspershouse.com>写在

消息新闻:eL ************** @ TK2MSFTNGP11.phx.gbl ...
Hi, Nick,

Do you have information when .NET Framework 2.0, VS.NET 2005 and SQL 2005
will be released? We are planning to use it for our next generation
applications. Thanks!

John
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eL**************@TK2MSFTNGP11.phx.gbl...
bie2,
如果您有一个应用程序检查自己的更新,您将需要一个单独的程序来完成它。该程序将加载启动画面,然后在发现需要更新时替换主应用程序可执行文件。否则,它只运行主应用程序。由于二进制文件已加载到CLR中,因此您无法删除该文件。

此外,您是否已查看过Microsoft的更新管理块?
或ClickOnce(如果你可以等待它,那么.NET 2.0即将发布。这两个都解决了这个问题,并且可能会减少你必须编写的代码量。

希望这会有所帮助。

-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse.com

" bie2" < TA ****** @ adelphia.net>在消息中写道
新闻:11 ********************** @ f14g2000cwb.googlegr oups.com ...
bie2,

If you have an application checking itself for updates, you will need a
separate program that does it. This program will load the splash screen,
and then replace the main application executable if it finds it needs an
update. Otherwise, it just runs the main application. Since the binary
is loaded into the CLR, you can''t delete the file.

Also, have you looked into the update management block from Microsoft?
Or ClickOnce (due out with .NET 2.0, if you can wait for it). Both of
these address this issue, and would probably reduce the amount of code you
have to write.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"bie2" <ta******@adelphia.net> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...


这就是我想做的事情:

1.启动应用程序。
2.启动在自己的线程中运行的SplashScreen。
3.我正在检查应用程序是否需要更新。
4.如果需要更新,请关闭SplashScreen并复制文件。
5.重新启动应用程序。 />
我的问题发生在第4步。我尝试了所有我知道的关闭SplashScreen,但我似乎无法做到。当
应用程序文件被替换时,它总是说
可执行文件被另一个进程使用。

如果我删除与SplashScreen相关的代码,一切正常
很好。

我试着使用以下代码调用SplashScreen中的函数:
ms_oThread.Abort();
ms_oThread.Join();
ms_oThread = null;

不工作。
任何人都知道我怎么能这样做?

谢谢
Hi,

Here''s what I want to do:

1. Start the application.
2. A SplashScreen running in its own thread is started.
3. I''m checking if the application needs an update.
4. If an update is needed I close the SplashScreen and copy the file.
5. Restart the application.

My problem is happening at step 4. I tried everything that I know to
close the SplashScreen, but I seems to be unable to do it. When the
application file is being replace it''s always saying that the
executable is used by another process.

If I remove the code related to the SplashScreen everything is working
fine.

I tried to call a function in the SplashScreen with this code:
ms_oThread.Abort();
ms_oThread.Join();
ms_oThread = null;

Was not working.
Anyone have any idea how I could be able to do that?

Thanks



John,


我能说的最好的是2005年第二季度(这是猜测) 。没有公司

发布日期已经确定。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


"约翰李 <乔*** @ newsgroup.nospam>在消息中写道

news:uo ************* @ TK2MSFTNGP15.phx.gbl ...
John,

The best I could say is 2nd quarter 2005 (and that is a guess). No firm
release dates have been set.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Lee" <jo***@newsgroup.nospam> wrote in message
news:uo*************@TK2MSFTNGP15.phx.gbl...
尼克,

当.NET Framework 2.0,VS.NET 2005和SQL 2005发布时,您是否掌握了相关信息?我们计划将它用于我们的下一代应用程序。谢谢!

John
Nicholas Paldino [.NET / C#MVP]" < mv*@spam.guard.caspershouse.com>在消息新闻中写道
:eL ************** @ TK2MSFTNGP11.phx.gbl ...
Hi, Nick,

Do you have information when .NET Framework 2.0, VS.NET 2005 and SQL 2005
will be released? We are planning to use it for our next generation
applications. Thanks!

John
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:eL**************@TK2MSFTNGP11.phx.gbl...
bie2,
如果您有一个应用程序检查自己的更新,您将需要一个单独的程序来执行更新。该程序将加载启动画面,然后在发现它时替换主应用程序可执行文件
需要更新。否则,它只运行主应用程序。由于二进制文件已加载到CLR中,因此您无法删除该文件。

此外,您是否已查看过Microsoft的更新管理块?
或ClickOnce(如果你可以等待它,那么.NET 2.0即将发布。这两个都解决了这个问题,并且可能会减少你必须编写的代码量。

希望这会有所帮助。

-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse.com

" bie2" < TA ****** @ adelphia.net>在消息中写道
新闻:11 ********************** @ f14g2000cwb.googlegr oups.com ...
bie2,

If you have an application checking itself for updates, you will need
a separate program that does it. This program will load the splash
screen, and then replace the main application executable if it finds it
needs an update. Otherwise, it just runs the main application. Since
the binary is loaded into the CLR, you can''t delete the file.

Also, have you looked into the update management block from Microsoft?
Or ClickOnce (due out with .NET 2.0, if you can wait for it). Both of
these address this issue, and would probably reduce the amount of code
you have to write.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"bie2" <ta******@adelphia.net> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...


这就是我想做的事情:

1.启动应用程序。
2.启动在自己的线程中运行的SplashScreen。
3.我正在检查应用程序是否需要更新。
4.如果需要更新,请关闭SplashScreen并复制文件。
5.重新启动应用程序。 />
我的问题发生在第4步。我尝试了所有我知道的关闭SplashScreen,但我似乎无法做到。当
应用程序文件被替换时,它总是说
可执行文件被另一个进程使用。

如果我删除与SplashScreen相关的代码,一切正常
很好。

我试着使用以下代码调用SplashScreen中的函数:
ms_oThread.Abort();
ms_oThread.Join();
ms_oThread = null;

不工作。
任何人都知道我怎么能这样做?

谢谢
Hi,

Here''s what I want to do:

1. Start the application.
2. A SplashScreen running in its own thread is started.
3. I''m checking if the application needs an update.
4. If an update is needed I close the SplashScreen and copy the file.
5. Restart the application.

My problem is happening at step 4. I tried everything that I know to
close the SplashScreen, but I seems to be unable to do it. When the
application file is being replace it''s always saying that the
executable is used by another process.

If I remove the code related to the SplashScreen everything is working
fine.

I tried to call a function in the SplashScreen with this code:
ms_oThread.Abort();
ms_oThread.Join();
ms_oThread = null;

Was not working.
Anyone have any idea how I could be able to do that?

Thanks




这篇关于如何在c#中杀死一个线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆