Killing the Threads or Tasks which are executing and having STA thread involved in their execution. RRS feed

  • Question

  • Hey I want to Kill the Threads or Tasks which are executing parallelly and each thread is having STA in it i.e. Dispatcher.Invoke(), So when i am trying to stop the thread execution using some flags which i set to true and false on any another UI event and then i check the flag and stop thread to enter in STA block.

    By doing this i can achieve the threads not going into STA and revert back where user wants but i cant stop their execution in background.

    The threads which are executing are working on large code of RestAPI calls and binding data on UI.

    Please suggest me something so that i can manage threads or tasks effectively

    • Edited by SudarshanD Thursday, March 28, 2019 5:13 AM
    Thursday, March 28, 2019 5:12 AM

All replies

  • The term "kill" in Windows typically is not something that should be done as the application's normal processing.

    There are many ways to do what you need to do but if I understand you then you can use an event such as AutoResetEvent Class (System.Threading).

    Sam Hobbs

    Thursday, March 28, 2019 6:59 AM
  • By using AutoResetEvent I can waitOne() the threads but they will go in hang state i want to kill them.

    They are no more useful for me to use Set() again.

    Friday, March 29, 2019 9:54 AM
  • They are no more useful for me to use Set() again.

    I don't understand what you mean there. The idea is that the threads can check the event periodically and if the event is set then it knows to return. You can use the same event for multiple threads, as relevant.

    Sam Hobbs

    Friday, March 29, 2019 3:12 PM