Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #10326 > unrolled thread

Terminating an application which runs in the background

Started byStefan Überbacher <info@sanosoft.com>
First post2017-03-23 00:17 -0700
Last post2017-03-23 03:54 -0700
Articles 18 — 4 participants

Back to article view | Back to comp.lang.clipper.visual-objects


Contents

  Terminating an application which runs in the background Stefan Überbacher <info@sanosoft.com> - 2017-03-23 00:17 -0700
    Re: Terminating an application which runs in the background "Wolfgang Riedmann" <wriedmann@gmail.com> - 2017-03-23 08:51 +0100
      Re: Terminating an application which runs in the background Stefan Überbacher <info@sanosoft.com> - 2017-03-23 01:10 -0700
        Re: Terminating an application which runs in the background "Wolfgang Riedmann" <wriedmann@gmail.com> - 2017-03-23 09:48 +0100
          Re: Terminating an application which runs in the background Stefan Überbacher <info@sanosoft.com> - 2017-03-23 02:30 -0700
            Re: Terminating an application which runs in the background "Wolfgang Riedmann" <wriedmann@gmail.com> - 2017-03-24 08:20 +0100
              Re: Terminating an application which runs in the background Karl Wochele <kw@ecos-system.invalid> - 2017-03-24 09:02 +0100
                Re: Terminating an application which runs in the background "Wolfgang Riedmann" <wriedmann@gmail.com> - 2017-03-24 09:17 +0100
                Re: Terminating an application which runs in the background "Wolfgang Riedmann" <wriedmann@gmail.com> - 2017-03-24 09:24 +0100
                  Re: Terminating an application which runs in the background Karl Wochele <kw@ecos-system.invalid> - 2017-03-24 10:05 +0100
                    Re: Terminating an application which runs in the background "Wolfgang Riedmann" <wriedmann@gmail.com> - 2017-03-24 10:29 +0100
              Re: Terminating an application which runs in the background Stefan Überbacher <info@sanosoft.com> - 2017-03-28 00:10 -0700
                Re: Terminating an application which runs in the background "Wolfgang Riedmann" <wriedmann@gmail.com> - 2017-03-28 09:54 +0200
                  Re: Terminating an application which runs in the background Stefan Überbacher <info@sanosoft.com> - 2017-03-28 04:09 -0700
                    Re: Terminating an application which runs in the background "Wolfgang Riedmann" <wriedmann@gmail.com> - 2017-03-28 14:28 +0200
    Re: Terminating an application which runs in the background Guy Deprez <dpzguy@skynet.be> - 2017-03-23 09:20 +0100
    Re: Terminating an application which runs in the background Karl Wochele <kw@ecos-system.invalid> - 2017-03-23 11:20 +0100
      Re: Terminating an application which runs in the background Stefan Überbacher <info@sanosoft.com> - 2017-03-23 03:54 -0700

#10326 — Terminating an application which runs in the background

FromStefan Überbacher <info@sanosoft.com>
Date2017-03-23 00:17 -0700
SubjectTerminating an application which runs in the background
Message-ID<0c459c45-4199-4fd7-acac-e6c5f2e66b58@googlegroups.com>
Hi,

application a calls application b, which runs in the background and is terminated when the user exits the application a. But when application a is terminated as a result of a runtime error, application b is still running.
I'm searching for a solution that ensures that application b is always terminated when application a terminates.

[toc] | [next] | [standalone]


#10327

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2017-03-23 08:51 +0100
Message-ID<ejhderF228pU1@mid.individual.net>
In reply to#10326
Hi Stefan,

> application a calls application b, which runs in the background and
> is terminated when the user exits the application a. But when
> application a is terminated as a result of a runtime error,
> application b is still running.  I'm searching for a solution that
> ensures that application b is always terminated when application a
> terminates.

this is possible with the Process API. You can search for a process
with the name you know and terminate it.

I suppose you need this for a VO application and not for a .NET one?
With .NET this would be easier than with VO.

Unfortunately, I cannot add an attachment here, but you can find it
here:

https://riedmann.it/download/RestartApp.zip

You'll find a small AEF that I'm using to restart an
application when updating itself. But please beware: this application
is not tested on a terminal server (in fact I'm pretty sure it will
behave not well there as they could be different processes with the
same name with different users).

Wolfgang





-- 

[toc] | [prev] | [next] | [standalone]


#10328

FromStefan Überbacher <info@sanosoft.com>
Date2017-03-23 01:10 -0700
Message-ID<f0134433-5172-428c-961b-2f119105a185@googlegroups.com>
In reply to#10327
Hi Wolfgang,

how do you terminate the child process when the calling process crashes as a result of a runtime error?

[toc] | [prev] | [next] | [standalone]


#10331

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2017-03-23 09:48 +0100
Message-ID<ejhgf5F2ku3U1@mid.individual.net>
In reply to#10328
Hi Stefan,

> how do you terminate the child process when the calling process
> crashes as a result of a runtime error?

the child process could monitor the father process and terminate itself
if the father process does not exist anymore.
Otherwise, if the child process is not under your control, you need a
third monitoring process.

In my sample you should find the functions to do that.

Wolfgang



-- 

[toc] | [prev] | [next] | [standalone]


#10332

FromStefan Überbacher <info@sanosoft.com>
Date2017-03-23 02:30 -0700
Message-ID<5a9a7f2c-3cf1-460a-aa98-7d1715b056bd@googlegroups.com>
In reply to#10331
Hi Wolfgang,

monitoring is an interesting approach.

When a VO runtime error occurs, there must be a possibility to perform an action before the application terminates. 

[toc] | [prev] | [next] | [standalone]


#10338

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2017-03-24 08:20 +0100
Message-ID<ejjvlmFhsc4U1@mid.individual.net>
In reply to#10332
Hi Stefan,

> monitoring is an interesting approach.
> 
> When a VO runtime error occurs, there must be a possibility to
> perform an action before the application terminates.

of course this is possible - and I do it all the time. Just install
your own error handler and it will be called when an error occurs. In
this error handler, depending on the situation, you could terminate the
child process.

Just seek for "ErrorBlock" in the online help.

Wolfgang

P.S. unfortunately such a powerful feature is missing in the .NET
framework



-- 

[toc] | [prev] | [next] | [standalone]


#10339

FromKarl Wochele <kw@ecos-system.invalid>
Date2017-03-24 09:02 +0100
Message-ID<ob2jq5$k8c$1@solani.org>
In reply to#10338
Hi Wolfgang,

 > P.S. unfortunately such a powerful feature is missing in the .NET
 > framework

I'm just taking my first steps in .NET. Somewhere I found somemthing 
similar to VO-Error-handling. Used this in my first app and it works 
pretty well. But please don't ask for explanations...

Karl

#using System.Windows.Forms
#using System.Drawing
#USING System.Threading

[STAThreadAttribute];
FUNCTION Start( asCmdLine AS STRING[] ) AS INT
	
	LOCAL oForm AS BasicForm
	
	Application.EnableVisualStyles()
	Application.DoEvents()

Application.ThreadException += 
ThreadExceptionEventHandler{MyThreadException}
AppDomain.CurrentDomain.UnhandledException += 
UnhandledExceptionEventHandler{MyUnhandledException}

	
	oForm := BasicForm{}
	Application.Run(oForm)

RETURN 0

STATIC FUNCTION MyThreadException(sender AS OBJECT,e AS 
ThreadExceptionEventArgs) AS VOID

HandleException(e.Exception)

RETURN

STATIC FUNCTION MyUnhandledException(sender AS OBJECT,e AS 
UnhandledExceptionEventArgs) AS VOID

HandleException((Exception)e.ExceptionObject)

RETURN

STATIC FUNCTION HandleException(e AS Exception) AS VOID

messagebox.show(	e.Message+;
						convert.tochar(13)+convert.tochar(10)+;
						convert.tochar(13)+convert.tochar(10)+;
						"Die Anwendung wird jetzt beendet...","Hinweis")
Application.Exit()

RETURN




Am 24.03.2017 um 08:20 schrieb Wolfgang Riedmann:
> Hi Stefan,
>
>> monitoring is an interesting approach.
>>
>> When a VO runtime error occurs, there must be a possibility to
>> perform an action before the application terminates.
>
> of course this is possible - and I do it all the time. Just install
> your own error handler and it will be called when an error occurs. In
> this error handler, depending on the situation, you could terminate the
> child process.
>
> Just seek for "ErrorBlock" in the online help.
>
> Wolfgang
>
> P.S. unfortunately such a powerful feature is missing in the .NET
> framework
>
>
>

[toc] | [prev] | [next] | [standalone]


#10340

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2017-03-24 09:17 +0100
Message-ID<ejk30kFigktU1@mid.individual.net>
In reply to#10339
Hi Karl,

> > P.S. unfortunately such a powerful feature is missing in the .NET
> > framework
> 
> I'm just taking my first steps in .NET. Somewhere I found somemthing
> similar to VO-Error-handling. Used this in my first app and it works
> pretty well. But please don't ask for explanations...


in VO you have a global unique errorhandler. In .NET, you have to call
it from several different places in try/catch sequences.

In VO, even if you have not a single begin/end sequence, your installed
error handler is called. In .NET unfortunately it is not that easy....

In my experience if you have not the try/catch sequence in the right
place, you'll receive the errors in the wrong places.

I have to confess that I have to find the best solution for my
applications yet - but there is so many new in .NET and WPF to learn,
that I have enough to do for the next 5 years at least....

Wolfgang


-- 

[toc] | [prev] | [next] | [standalone]


#10341

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2017-03-24 09:24 +0100
Message-ID<ejk3daFiiv4U1@mid.individual.net>
In reply to#10339
Hi Karl,

> > P.S. unfortunately such a powerful feature is missing in the .NET
> > framework
> 
> I'm just taking my first steps in .NET. Somewhere I found somemthing
> similar to VO-Error-handling. Used this in my first app and it works
> pretty well. But please don't ask for explanations...


maybe I have to add that I use WPF, and sometimes also GUI agnostic
DLLs. Therefore I cannot simply popup an error box.

This is one of the things I use everywhere:

static method LogException( oEx as Exception ) as void
local oData as IDictionary
local cLogFile as string
local oLines as List<string>
	
oLines := List<string>{}
oLines:Add( "" )
oLines:Add( "class name:" + oEx:GetType():Name )
oLines:Add( "Message:" + oEx:Message )
oLines:Add( "Source:" + oEx:Source )
oLines:Add( "StackTrace:" + oEx:StackTrace )
oData := oEx:Data
if oData != null_object
  oLines:Add( "Data:" )
  if oData:Count > 0
    foreach oEntry as DictionaryEntry in oData
      oLines:Add( oEntry:Key:ToString() + ":" + oEntry:Value )
    next
  endif
endif
	
cLogFile := Path.Combine( Utility.ProgramPath(), "XSError.log" )
File.AppendAllLines( cLogFile, oLines )
	
if oEx:InnerException != null_object
  oLines:Clear()
  oLines:Add( "" )
  oLines:Add( "InnerException:" )
  File.AppendAllLines( cLogFile, oLines )
  Utility.LogException( oEx:InnerException )
end
	
return

Wolfgang






-- 

[toc] | [prev] | [next] | [standalone]


#10342

FromKarl Wochele <kw@ecos-system.invalid>
Date2017-03-24 10:05 +0100
Message-ID<ob2ngd$msv$3@solani.org>
In reply to#10341
Hi Wolfgang,

the relevant lines in the START-function are

Application.ThreadException += 
ThreadExceptionEventHandler{MyThreadException}
AppDomain.CurrentDomain.UnhandledException += 
UnhandledExceptionEventHandler{MyUnhandledException}

Then all errors will end in Handleexception(). There you can do whatever 
you want...

Karl

[toc] | [prev] | [next] | [standalone]


#10343

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2017-03-24 10:29 +0100
Message-ID<ejk78oFjbosU1@mid.individual.net>
In reply to#10342
Hi Karl,

at least the line 

AppDomain.CurrentDomain:UnhandledException +=
AppDomainUnhandledException

is present in my application. I'll try also the other statement.

Wolfgang



Karl Wochele wrote:

> Hi Wolfgang,
> 
> the relevant lines in the START-function are
> 
> Application.ThreadException +=
> ThreadExceptionEventHandler{MyThreadException}
> AppDomain.CurrentDomain.UnhandledException +=
> UnhandledExceptionEventHandler{MyUnhandledException}
> 
> Then all errors will end in Handleexception(). There you can do
> whatever you want...
> 
> Karl



-- 

[toc] | [prev] | [next] | [standalone]


#10355

FromStefan Überbacher <info@sanosoft.com>
Date2017-03-28 00:10 -0700
Message-ID<7d5647d5-00c2-4061-b082-5a6b1364bace@googlegroups.com>
In reply to#10338
> of course this is possible - and I do it all the time. Just install
> your own error handler and it will be called when an error occurs. In
> this error handler, depending on the situation, you could terminate the
> child process.

But then you must overwrite the DefError function, loosing its handling, right?

At all, the DefError function does not stand for object oriented programming. The handling of DefError should be in a class, from which a developer could derive its own class. 

[toc] | [prev] | [next] | [standalone]


#10356

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2017-03-28 09:54 +0200
Message-ID<ejuj63Fl123U1@mid.individual.net>
In reply to#10355
Hi Stefan,

> > of course this is possible - and I do it all the time. Just install
> > your own error handler and it will be called when an error occurs.
> > In this error handler, depending on the situation, you could
> > terminate the child process.
> 
> But then you must overwrite the DefError function, loosing its
> handling, right?

yes. But you have two possibilities: 
- copy the DefError code to your own error handler and enhance it. 
- keep a copy of the DefError handler somewhere and chain it

> At all, the DefError function does not stand for object oriented
> programming. The handling of DefError should be in a class, from
> which a developer could derive its own class.

please don't forget that the DefError concept is more than 20 years
old, and was taken over from Clipper.

But if you like, of course you can rewrite the complete error system of
Visual Objects - instead of a codeblock you can also use an object with
an Eval() method (unfortunately this fact is not widely known, but
permits also detached locals as part of this object).

Wolfgang



-- 

[toc] | [prev] | [next] | [standalone]


#10357

FromStefan Überbacher <info@sanosoft.com>
Date2017-03-28 04:09 -0700
Message-ID<e4b47f28-9812-4b27-a075-849b35d6f351@googlegroups.com>
In reply to#10356
Hi Wolfgang,

I'd rather prefer something like that:
when a VO System error occurs, get the App object (GetAppObject) and fire a handler let's say SysError. The question is only where to call it.

[toc] | [prev] | [next] | [standalone]


#10358

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2017-03-28 14:28 +0200
Message-ID<ejv36vFo9t9U1@mid.individual.net>
In reply to#10357
Hi Stefan,

> I'd rather prefer something like that:
> when a VO System error occurs, get the App object (GetAppObject) and
> fire a handler let's say SysError. The question is only where to call
> it.

to be called, you have two possibilities:

- be notified in a begin/end sequence inthe recover statement. The only
drawback is that you have to have to insert your code in every recover
branch of every begin/end sequence (in my programs, this would be a
major problem as I use them a lot)
- replace the default error handler by your own

Personally I prefer the second option (and I use it very often:
immagine a Windows service that pops up the standard error dialog: I
prefer an email with the runtime error instead).

You can find the original DefError function in the System Library SDK,
module ErrorSys.

We have to take the system as it is and try to make the best of it. I
had very few things I was not able to accomplish with VO (and some of
them could be accomplished building a COM module with X#)

Wolfgang



-- 

[toc] | [prev] | [next] | [standalone]


#10330

FromGuy Deprez <dpzguy@skynet.be>
Date2017-03-23 09:20 +0100
Message-ID<mu07dcpv61rg95r30j4fgdngc70nburear@4ax.com>
In reply to#10326
Hi,
You could implement something like this using the functions below...:

Method Timer() class MyMainWindow
local hwnd as PTR
AEval(GetAllTopLevelWindows(),{|h| iif(GetWindowCaption(h) = "ITCharts
Advanced",hwnd:=h,NIL)} )
IF hwnd = NULL_PTR
	//App is out
	Close MyMainWindow
endif
---------------------------------
 FUNCTION GetAllTopLevelWindows() AS ARRAY PASCAL

LOCAL aWindows AS ARRAY
LOCAL ptrCallBackFunction AS AddTopLevelWindowToArray PTR
aWindows:=ArrayCreate(0)
ptrCallBackFunction	:= @AddTopLevelWindowToArray()
EnumWindows(ptrCallBackFunction,LONGINT(_CAST,aWindows))
/*
	--> ==
EnumWindows(@AddTopLevelWindowToArray(),LONGINT(_CAST,aWindows))
*/
RETURN aWindows
STATIC FUNCTION AddTopLevelWindowToArray(hWnd AS PTR,aWindows AS
ARRAY) AS WORD CALLBACK
 AAdd(aWindows,hWnd)
RETURN 1
FUNCTION GetWindowCaption(hWindow AS PTR) AS STRING
LOCAL pCaption AS PSZ
LOCAL cCaption AS STRING

pCaption := MemAlloc(1024)
GetWindowText(hWindow,pCaption,1024)
cCaption := Psz2String(pCaption)
MemFree(pCaption)

RETURN AllTrim(cCaption)
On Thu, 23 Mar 2017 00:17:46 -0700 (PDT), Stefan Überbacher
<info@sanosoft.com> wrote:

>Hi,
>
>application a calls application b, which runs in the background and is terminated when the user exits the application a. But when application a is terminated as a result of a runtime error, application b is still running.
>I'm searching for a solution that ensures that application b is always terminated when application a terminates.

[toc] | [prev] | [next] | [standalone]


#10334

FromKarl Wochele <kw@ecos-system.invalid>
Date2017-03-23 11:20 +0100
Message-ID<ob07h2$utp$1@solani.org>
In reply to#10326
Hi Stefan,

start app b from app a with a commandline parameter:
ntrim(GetCurrentProcessId())

in app b:
pHandle := OpenProcess(PROCESS_ALL_ACCESS,FALSE,val(cProcessId))

with a timer you can check:

local dwExit as dword
If GetExitCodeProcess(pHandle,@dwExit)
	if dwExit <> STILL_ACTIVE
		Quit()
	endif
endif

HTH,
Karl

Am 23.03.2017 um 08:17 schrieb Stefan Überbacher:
> Hi,
>
> application a calls application b, which runs in the background and is terminated when the user exits the application a. But when application a is terminated as a result of a runtime error, application b is still running.
> I'm searching for a solution that ensures that application b is always terminated when application a terminates.
>

[toc] | [prev] | [next] | [standalone]


#10335

FromStefan Überbacher <info@sanosoft.com>
Date2017-03-23 03:54 -0700
Message-ID<85064a57-2179-4d68-b284-269b8807d5c9@googlegroups.com>
In reply to#10334
Hi Karl,

this is an interesting approach.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.clipper.visual-objects


csiph-web