473,325 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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.Abort();
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 15183
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...
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

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.com> wrote in
message news:eL**************@TK2MSFTNGP11.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.com

"bie2" <ta******@adelphia.net> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.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.Abort();
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.com

"John Lee" <jo***@newsgroup.nospam> wrote in message
news:uo*************@TK2MSFTNGP15.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,

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...
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



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.ExitThread should do it.
ms_oThread.Abort();


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

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

The function I'm calling is static . In this function I have this:
ms_oThread = new Thread( new
ThreadStart(SplashScreen.ShowForm));
ms_oThread.IsBackground = true;
ms_oThread.ApartmentState = ApartmentState.STA;
ms_oThread.Start();

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******@adelphia.net> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.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
I agree, but the problem is that to check for an update it's done
through the web and this can maybe take some time.
So I wanted a splash saying "Checking for an update".

Nov 16 '05 #11
Hi,

What stop you from using a win app for doing the check?

cheers,

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

"bie2" <ta******@adelphia.net> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I agree, but the problem is that to check for an update it's done
through the web and this can maybe take some time.
So I wanted a splash saying "Checking for an update".

Nov 16 '05 #12

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:OQ**************@TK2MSFTNGP14.phx.gbl...
John,

The best I could say is 2nd quarter 2005 (and that is a guess). No
firm release dates have been set.


I've heard 3rd quarter at the earliest, and even that may be pushed back

Nov 16 '05 #13
David Levine <no******************@wi.rr.com> wrote:
The best I could say is 2nd quarter 2005 (and that is a guess). No
firm release dates have been set.


I've heard 3rd quarter at the earliest, and even that may be pushed back


When was that, out of interest? I haven't heard anything beyond "H1"
officially, with unofficial suggests of late in Q2. It'll be a real
shame if it isn't out until Q3 :(

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #14
As best as I can recall, I heard it about a month or two ago. We originally
needed it around the August time frame and then we were told that it would
be held up at least a month or two, so now it's looking like September or
so - caused us to drop Whidbey and plan on using v1.1. These dates are iffy
and can very well change. I can get more current info if you need it...I can
forward the request on to my MSFT contact.
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP***********************@msnews.microsoft.co m...
David Levine <no******************@wi.rr.com> wrote:
> The best I could say is 2nd quarter 2005 (and that is a guess). No
> firm release dates have been set.


I've heard 3rd quarter at the earliest, and even that may be pushed back


When was that, out of interest? I haven't heard anything beyond "H1"
officially, with unofficial suggests of late in Q2. It'll be a real
shame if it isn't out until Q3 :(

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #15
I tought about that at the beginning but if I changed this "updater"
I'll need to do the update it also.
But I think now it's the only solution that can be worth exploring.
I'll try to make it the most generic possible so I won't have any
update to do.

Thanks for your answers

Nov 16 '05 #16
http://blogs.msdn.com/askburton/arch...07/348928.aspx

Beta2 is scheduled Q1 2005, PDC in September 2005. So my guess is that they
are planning a RC or at best RTM in September .

Willy.

"David Levine" <no******************@wi.rr.com> wrote in message
news:Ou****************@TK2MSFTNGP11.phx.gbl...

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:OQ**************@TK2MSFTNGP14.phx.gbl...
John,

The best I could say is 2nd quarter 2005 (and that is a guess). No
firm release dates have been set.


I've heard 3rd quarter at the earliest, and even that may be pushed back

Nov 16 '05 #17

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

Similar topics

12
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...
5
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...
6
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...
3
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...
9
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...
2
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...
5
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...
18
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...
20
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...
1
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.