Threading!!!

  • Thread starter Thread starter Vai2000
  • Start date Start date
V

Vai2000

Hi All, I have a Console EXE which calls a Thread...inside its module. I
want to spawn the thread in such a way that if the console.exe is killed, my
thread keeps on running ...until it finishes up


TIA
 
Hi All, I have a Console EXE which calls a Thread...inside its module. I
want to spawn the thread in such a way that if the console.exe is killed, my
thread keeps on running ...until it finishes up

TIA

Try to set the IsBackground property of your Thread instance to true.
I think that should do it (not sure, though).

Regards,

Dan
 
Hi All, I have a Console EXE which calls a Thread...inside its module. I
want to spawn the thread in such a way that if the console.exe is killed, my
thread keeps on running ...until it finishes up

TIA


In most of my applications, I usually am trying to make sure my
threads are gone ASAP, so this is a new one to me. The times when my
thread DOESN'T go away immediately, I have "IsBackground" is set to
false.

Then on the app-exit or the module dispose event, call
YourThread.Join(X) where X is a valid number of seconds to wait before
disposing the threads entirely.

The catch with this, I've found is that most of the time it will wait
EXACTLY X milliseconds, even if the threads are all gone.

An even better method might be to keep an ArrayList of running threads
in the module. On module dispose, While ArrayList.Count > 0,
Thread.Sleep(...) for a small slice of time. For safety, I'd put a max
counter in there to ke your app from hanging indefinately. But that's
probably just me being paranoid about runaway processes.

There may be an even slicker solution to this, but that's just my
suggestion. Hope it helps.

--Sim
 
Vai2000 said:
Hi All, I have a Console EXE which calls a Thread...inside its module. I
want to spawn the thread in such a way that if the console.exe is killed, my
thread keeps on running ...until it finishes up


TIA

It's not possible to have running threads after the process has died, when the OS receives a
command to kill a process, it will kill all threads cold, and remove the process from the
system.

Willy.
 
Hi All, I have a Console EXE which calls a Thread...inside its module. I
want to spawn the thread in such a way that if the console.exe is killed, my
thread keeps on running ...until it finishes up

All threads run within a process. If you kill the process, you kill
all the threads within the process. Therefore if you need your new
thread to run even if the originating process is killed, you need to
run it in a new process.

Jon
 
When the console app closes, the CLR will issue a command to close the
application domain which will try to stop all the threads. This will cause a
thread abort exception on the thread will you can handle and ignore but the
app domain will forcibly close after 40 seconds.
Why does it need to be a console app. It is possible to write a windows
forms app without a form so the user doesnt notice it.
 
Hi,

Vai2000 said:
Hi All, I have a Console EXE which calls a Thread...inside its module. I
want to spawn the thread in such a way that if the console.exe is killed,
my
thread keeps on running ...until it finishes up

What u want is not possible, if the "main" thread ends the program ends.

What you need to do is spawn a new process and create it in such a way that
no interface is used. Take a look at the Process class and the different
options of startup. You can create a console app without showing the
console.
 
Ignacio Machin ( .NET/ C# MVP ) said:
Hi,



What u want is not possible, if the "main" thread ends the program ends.
Not exactly, the OS has no notion of "main" threads, the OS kills the threads in the process
and removes them from the scheduler list, when all threads are removed from the scheduler,
he removes the process from the process list.
Only threads that are blocked in kernel keep hmmm "running", that's why it's possible to
have processes still running after being killed.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top