473,732 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to kill a thread in c#?

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.Abor t();
ms_oThread.Join ();
ms_oThread = null;

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

Thanks

Nov 16 '05 #1
16 15214
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.co m

"bie2" <ta******@adelp hia.net> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
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.Abor t();
ms_oThread.Join ();
ms_oThread = null;

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

Thanks

Nov 16 '05 #2
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.c om> wrote in
message news:eL******** ******@TK2MSFTN GP11.phx.gbl...
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.co m

"bie2" <ta******@adelp hia.net> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
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.Abor t();
ms_oThread.Join ();
ms_oThread = null;

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

Thanks


Nov 16 '05 #3
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.co m

"John Lee" <jo***@newsgrou p.nospam> wrote in message
news:uo******** *****@TK2MSFTNG P15.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.c om> wrote
in message news:eL******** ******@TK2MSFTN GP11.phx.gbl...
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.co m

"bie2" <ta******@adelp hia.net> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
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.Abor t();
ms_oThread.Join ();
ms_oThread = null;

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

Thanks



Nov 16 '05 #4
bie2 wrote:
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.
How do you create the splash screen? What code runs Application.Run ?

Note that you have two totally different objects, the .NET Form object and
the Windows window. You have to synchronize the lifetime of each, and
synchronize them with the message queue. The message queue is created by
Application.Run and this keeps the main thread alive. If the main thread is
kept alive, then the application is kept alive. If the application is alive
then you cannot overwrite the process's file.
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.
That's because it is. You may close the splash screen, but you've not closed
the process. Instead, spawn a new process that copies the file, but get it
to wait for a short time before it does this. After starting the new
process, close down the app with the splash screen. Depending on how you
show the splash screen, or how the rest of the app works determines how you
do this. In most cases Application.Exi tThread should do it.
ms_oThread.Abor t();


NEVER call Thread.Abort, that is a horrible way to kill a thread.

Richard
--
www.richardgrimes.com
my email ev******@zicf.b et is encrypted with ROT13 (www.rot13.org)
Nov 16 '05 #5
On Mon, 10 Jan 2005 12:23:19 -0800, "John Lee"
<jo***@newsgrou p.nospam> wrote:
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!


The latest official statement is Summer '05. (
http://blogs.msdn.com/askburton/arch...07/348928.aspx )

Austin
Nov 16 '05 #6
Here's how the application is structured

When the main application is started, before doing an Application.Run I
call the SplashScreen function ShowSplashScree n.

The function I'm calling is static . In this function I have this:
ms_oThread = new Thread( new
ThreadStart(Spl ashScreen.ShowF orm));
ms_oThread.IsBa ckground = true;
ms_oThread.Apar tmentState = ApartmentState. STA;
ms_oThread.Star t();

In the function ShowForm I have this:
ms_frmSplash = new SplashScreen();
Application.Run ( ms_frmSplash );

Thanks for your answer.

Nov 16 '05 #7
Hi,
2. A SplashScreen running in its own thread is started.
The main thread should be the only one interacting with the screen, create a
worker thread instead.
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.


It may due the fact that you create the form in another thread.
The other problem is logic, if you are running the applicacion you cannot
overwrite it.

Solution
1- Create a Splash application , do the check and then using Process.Start
load the "real" application, after that you can close the splash
Tip 1: You can make the Splash screen to stick in the foreground while the
app is loaded in the background
Tip 2: You could use some IPC to inform the splash app that the real app is
loaded and it can get close

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Nov 16 '05 #8
Here more precision, that I left out.

When an update is necessary, I start a new process with an application
that will do the update.
The thing I don't understand is that I don't see anymore the process
for the main application. And it's still saying that the file cannot be
copied because a process is still using it.

Is it possible that the new process (the one for the update) is locking
my application?

Nov 16 '05 #9
Hi,

Do the opposite start running the application that checks for update, if
there is one download & install it then start the real application

It's much easier that way

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"bie2" <ta******@adelp hia.net> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
Here more precision, that I left out.

When an update is necessary, I start a new process with an application
that will do the update.
The thing I don't understand is that I don't see anymore the process
for the main application. And it's still saying that the file cannot be
copied because a process is still using it.

Is it possible that the new process (the one for the update) is locking
my application?

Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
18892
by: Jerry Sievers | last post by:
Greetings Pythonists; I have limited experience with threaded apps and plenty with old style forked heavyweight multi-processing apps. Using Python 2.3.3 on a Redhat 7.x machine. Wondering if there is a simple way from a main python program to kill a running thread? I see with the 'threading' module the way daemonic threads behave when the main program finishes.
5
10937
by: Blatwurst | last post by:
I'm trying to implement a simple server in C#. I want to do the classic thing of spinning off a thread that just blocks in a Socket.Accept() call until a request comes in. At that point, the Accept() returns, the thread spins off another thread to handle the request, and then calls Accept() again. This all works fine except that I can find no way to kill the thread that is blocked in the Accept() call when I want to shut down the server. ...
6
42877
by: RickDee | last post by:
Understand that when I start a thread, a number will be generated and is able to get from GetHashCode method. But I would like to use this number when I want to kill certain thread, anybody know how ?? Thanks Regards
3
5851
by: Stewart | last post by:
Hey Group, Hoping someone can help me out. I have some code which starts up some asynchronous code using a delegate. The code is below. Basically my main code (not shown) calls ServerThreadStart.StartServer to start the server running asynchronously. This works fine. Shouldn't be any problems here. My question is how can I get my code to kill this code running asynchronously? There is a dlgtServer.Remove(Delegate, Delegate)
9
15284
by: Brett | last post by:
I'm trying to kill a thread spawned this way: Form1 spawns Class1 via Thread.start() Here's my code to kill the thread: If (t.ThreadState.ToString = "SuspendedRequested, WaitSleepJoin") Or (t.ThreadState.ToString = "Suspended") Or (t.ThreadState.ToString = "WaitSleepJoin, Suspended") Then Else t.Abort()
2
3504
by: Christopher Carnahan | last post by:
I need to figure out how to terminate a thread while it is blocked trying to create a COM object via interop. In a worker thread, I do something like this: Type t = null; Object activatedObject = null; Legacy.IScheduled comObject = null; t = Type.GetTypeFromProgID(ProgID);
5
10599
by: care02 | last post by:
Hi! I have the following problem: I have written a short Python server that creates an indefinite simulation thread that I want to kill when quitting (Ctrl-C) from Python. Googling around has not given me any hints on how to cleanly kill running threads before exiting. Any help is appreciated! Carl
18
10240
by: =?Utf-8?B?VGhlU2lsdmVySGFtbWVy?= | last post by:
Because C# has no native SSH class, I am using SharpSSH. Sometimes, for reasons I do not know, a Connect call will totally lock up the thread and never return. I am sure it has something to do with weirdness going on with the server I am talking to. Anyhow, this locked up state happens once in a while (maybe once per day) and I can't figure out how to deal with the locked up thread. If I issue a Thread.Abort() the exception never...
20
5092
by: =?ISO-8859-1?Q?Gerhard_H=E4ring?= | last post by:
John Dohn wrote: When I do this, I put a special value in the queue (like None) and in the worker thread, check for the special value and exit if found. Threads can also be marked as "daemon threads" (see docs for threading.Thread objects). This will make the application terminate if only "daemon threads" are left. So best would probably be soemthing like
1
10385
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi misters, Is it possible "kill" the thread of Backgroundworker ? In my Dowork event, I have NOT While for do e.Cancel = true, only have a call to external COM. If I want cancel, calling CancelAsync, not cancels the call to COM. How I can do it , please ? Any suggestions will be very appreciated.
0
8944
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8773
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9445
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9306
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6733
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6030
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3259
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2177
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.