Is it possible to stop all generated threads of an application in C #? That is, if applications create 2 streams, and each of them creates another stream. Is it possible in this case to stop all threads?

    4 answers 4

    1. By generating a stream, memorize it in some global list.
    2. Then bypass this list and call the Abort method for each thread.
    3. It is impossible to get a list of running threads through the standard API of the datnet. You can get a list of OS threads, but does not match the list of managed threads.
    • Yes, thanks, there was one little idea using List <Thread>, you have to try :) - zMaXz

    You can loop through all the process threads and kill them. You can iterate through all the threads of a process using the functions CreateToolhelp32Snapshot, Thread32First, Thread32Next. Here is an example

    • Actually, your example is in C / C ++, not C # - Modus

    NtSuspendProcess. For the current process there will be a deadlock.

      End the current process. When it is completed, all its threads will be stopped.

      • At the end of the process all threads are completed. - Indy
      • @Indy is exactly what is required for the question, and you just repeated my answer. - IAZ
      • @IAZ: Indy is probably aware of some secret difference between threads and threads. - Nick Volynkin