0 Replies Latest reply on Mar 3, 2013 2:18 PM by tinu8805

    How long does a thread exist?

    tinu8805

      hi there

       

      I have a page in CF10 that kicks a thread for a device emulation. the thread is done like this:

       

      ---

            thread action="run" name="MCUThread" {

               try {

                  for (thread.i = 1; thread.i lte maxseqlen; thread.i++) {

                     session.mcu.emulateTickClock ();

                     sleep(1);         // do we need it or not ... other threads seem not to work or get no time to work

                     WsSendMessage ('{ "Op":"Info","Text":"MCU step #thread.i#" }');

                  }

                  WsSendMessage ('{ "Op":"Info","Text":"The MCU bout is done. MCU is destroyed" }');

               } catch (any e) {

      writedump (var=#e#, format="html", output="v:\temp\exception.htm");

               }

            }

      ---

       

      This works because the thread pushes out 6000 steps and the destroy message.

       

      This call is within a cfc that is invoked by a client websocket invocation.

       

      On the client, tere is a js-function that invokes the thread. the button to execute the js-function can be pressed once and the thread rns.

       

      Once the thread is done (i.e. the loop is done and the destroy message is shown), pressing the button again generates this error:

       

      ---

      Thread with name MCUTHREAD could not be created. Thread names must be unique within a page.

      ---

       

      Howerver, the thread is supposed to be gone?

       

      Thanks for some insight ...

       

      Martin

       

       

      FWIW: I did a kullMCUThread like this. it is called before the startMCU call - to no avail

       

      ---

         private void function killMCUThread () {

            try {

               if (StructKeyExists (cfthread, "MCUThread")) {

                  WsSendMessage ('{ "Op":"Info","Text":"killMCUThread: MCU thread is still active with status #cfthread["MCUThread"].Status#. Terminating ..." }');

                  //Thread is still there -> try to terminate

                  if ("NOT_STARTED,RUNNING" contains cfthread["MCUThread"].Status) {

                     thread action="terminate" name="MCUThread";

                     sleep (1000);

                  }

                  try {

                     WsSendMessage ('{ "Op":"Info","Text":"killMCUThread: ERROR MCU thread is still active ater killing with status #cfthread["MCUThread"].Status#." }');

                  } catch (any e) {

                  }

                  WsSendMessage ('{ "Op":"Info","Text":"MCUThread terminated." }');

               } else {

                  WsSendMessage ('{ "Op":"Info","Text":"MCUThread is still active. Terminating ..." }');

               }

            } catch (any e) {

               writedump (var=#e#, format="html", label="ERROR in killMCUThread", output="v:\temp\exception.htm");

            }

         }

      ---