dpWaitForValue in a new thread cancelled after PanelOff() in original thread;

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
4 posts • Page 1 of 1
jonred
Posts:36
Joined: Mon Mar 06, 2017 10:24 am

dpWaitForValue in a new thread cancelled after PanelOff() in original thread;

Post by jonred »

Hi everyone,

I`m trying to make a timer that switch off a vent after a set time from the swithing on.
I have a Yes/No panel to comfirm the order, and the code associated to the yes button.
I then call the dpWaitForValue in a new thread and then close the panel with panelOff, but the thread stops.
Commenting the panelOff line allows the execution of dpWait.

I thought the new thread was not dependat from the parent, but it doesn´t seem that way.
Is there any solution or anther way of doing it?

The idea is to switch off the any number of vents after a set period of time, unless the vent is manually switched off, so the automatic off is cancelled.
the vents have a button to send the order that opens a confirmation window, and associated to the click event is the code:

Code: Select all

main()
{
string ordenes;
dyn_string buffer;
  
     if(isDollarDefined("$valor")){
      dpSet($dp,$valor);
           }
    else{ 
    ordenes=$dp; 
     strreplace(ordenes,"_marcha_rapida","_paro");
     strreplace(ordenes,"_marcha_lenta","_paro");
     ordenes+=":_original.._value";
   startThread("marchaTemp",ordenes);
    //dpGet("pulso_3s.buffer1:_online.._value",buffer);
 
 // dynAppend(buffer, ordenes);
  //dpSet("pulso_3s.buffer1:_original.._value",buffer);
}
  PanelOff();//if i comment this line, it works

}

void marchaTemp(string dp)
{
time t;
dyn_string dpNamesWait, dpNamesReturn;
dyn_anytype conditions, returnValues;
int status;
dpNamesWait = makeDynString(dp);
conditions[1]=true;
dpNamesReturn = makeDynString(dp);
t=10;
status = dpWaitForValue( dpNamesWait, conditions, dpNamesReturn, returnValues, t );
if ( status == -1 )
{
DebugN( "Error" );
DebugN( "dpNamesWait : " + dpNamesWait );
DebugN( "conditions : " + conditions );
DebugN( "dpNamesReturn : " + dpNamesReturn );
DebugN( "returnValues : " + returnValues );
}
else if ( dynlen(getLastError()) != 0 )
{
DebugN( "Error returned in message" );
// Reaction: , for example, output
DebugN( getLastError() );
DebugN( "dpNamesWait : " + dpNamesWait );
DebugN( "conditions : " + conditions );
DebugN( "dpNamesReturn : " + dpNamesReturn );
DebugN( "returnValues : " + returnValues );
}
else
{
DebugN( "everything ok" );
DebugN( "dpNamesWait : " + dpNamesWait );
DebugN( "conditions : " + conditions );
DebugN( "dpNamesReturn : " + dpNamesReturn );
DebugN( "returnValues : " + returnValues );
}

}
i suposse i could make a solution using _TimedFunction, but there is no a simple way of use a countdown timer?

i am using version WinCCOA 3.10 SP1

Thank you very much

fmulder
Posts:330
Joined: Wed Feb 03, 2010 9:46 am

Re: dpWaitForValue in a new thread cancelled after PanelOff() in original thread;

Post by fmulder »

The script code in a panel (even a callback or a thread) will simply disappear when you close the panel. The thread wont gracefully stop... it is simply gone.
It seems that you want to start something that keeps on running when the panel closes. There are two solutions to this:

1) You can use a panel in your application that never goes away. E.g. like the basepanel that propably opened your popup panel
2) or let a script tun on the server

If this is something that needs to run when a person is logged in, then do it in a 'global' panel in your GUI. If it is something that should be run by the server then do it in a script manager

share the fun
Frenk Mulder

jonred
Posts:36
Joined: Mon Mar 06, 2017 10:24 am

Re: dpWaitForValue in a new thread cancelled after PanelOff() in original thread;

Post by jonred »

OK, thank you, il do it with a script

Gertjan van Schijndel
Posts:634
Joined: Mon Aug 02, 2010 10:37 am

Re: dpWaitForValue in a new thread cancelled after PanelOff() in original thread;

Post by Gertjan van Schijndel »

Perhaps you could move your code to the parent panel and execute it if the child panel returns the right value (by using a 'ChildPanelOn*Return' function).

4 posts • Page 1 of 1