Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ShowMessage in Service halts process

Posted on 2009-03-29
5
Medium Priority
?
1,743 Views
Last Modified: 2013-11-22
I created a service (i.e. runs as a service, not an application).  I found afterwards it was calling a piece of code which had a showmessage contained in it.  Consequently it was halting continuation.

Short of ensuring my code does not contain any showmessages, are there any alternatives?  A lot of this code is used in win applications.


0
Comment
Question by:markschenkel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 1

Assisted Solution

by:pmunro
pmunro earned 100 total points
ID: 24014479
If you set the service to not interact with the desktop, this should stop the messages popping up and pausing the services running.
0
 
LVL 3

Assisted Solution

by:btframework
btframework earned 100 total points
ID: 24014727
By default windows NT (4.0, 2000, XP, Vista) has "two" desktops. One is for user and other one is system. You may see the system desktop before login.
So any service in the system by default uses system desktop. You should switch it to user desktop before showing any messages, dialogs or something like that.
Any way, take a look at this please: http://articles.techrepublic.com.com/5100-10878_11-1050538.html
0
 
LVL 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 300 total points
ID: 24018951
create a unit with a ShowMessage procedure/function which you let it call Dialogs when in an ordinary app or logs the message to file when in a service application


unit AppMessenger;
 
interface
 
implementation
 
uses Dialogs, SvcMgr;
 
const
  ServiceAppName = 'ServiceApp';
 
  fServiceApp: integer = 0;
  fEventLogger: TEventLogger = nil;
 
function IsServiceApp: boolean;
begin
  if fServiceApp = 0 then
  begin
    if Assigned(SvcMgr.Application) then
    begin
      fServiceApp := 2;
      fEventLogger := TEventLogger.Create(ServiceAppName);
    end else
      FServiceApp := 1;
  end;
  Result := fServiceApp = 2;
end;
 
procedure ShowMessage(const Msg: string);
begin
  if IsServiceApp then
    fEventLogger.LogMessage(Msg)
  else
    Dialogs.ShowMessage(Msg);
end;
 
end.

Open in new window

0
 

Accepted Solution

by:
markschenkel earned 0 total points
ID: 24032214
<<If you set the service to not interact with the desktop, this should stop the messages popping up and pausing the services running.>>
I experimented with this setting.  When it is unchecked the service simply hangs (I guess it is probably displaying a message on the desktop btframework alludes to).  But when checked it displays the showmessage on the desktop (and of course halts the app).

I have seen similar like solutions to Geert_Gruwez.  What I was hoping for was a solution which would detect any showmessages at compile time.  Is it possible to detect if ShowMessage is compiled??? (assuming if it is not used the optimizer removes it)

Ultimately I guess this rests with cautious/careful coding practices.  
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 24036745
it will allways be compiled when you use the dialogs unit
the trick is to fool delphi to use your own unit by placing it last in the uses list
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question