DDE and application initialisation time - timeout

Our application is DDE enabled. It acts as a server. It has its own file type, and offers an 'Open' command.
When launching application from a right-click on a saved file (ie reading HKEY_CLASSES_ROOT-----\shell etc) we sometimes get "there was a problem sending the command to the program". Especially win10.
On problem PCs we test a VBA script that triggers our exe, waits a second, and then sends DDE commands. This works well.
We conclude we need a pause, or to increase timeout on the DDE conversation.
Can this be done?
Is there a globally effective registry setting?
Any ideas?

No, you cannot pause or increase the DDE timeout.
Instead, you should look at possible problems with your application.
It is likely that your program is starting to pump messages before your DDE server is up and running. As soon as you start handling messages, Windows assumes your DDE server is running. So, it sends you the message, but your server is not up to receive it yet. Make sure that no thread in the program is handling Windows messages before the DDE server is setup.

Related

Cleaning up running FireDAC TTasks when closing application

I have a program (in Delphi 10.3) that allows the user to configure FireDAC database access at run time using the standard dialog as provided by the libraries (as listed in FireDAC help)
TfrmFDGUIxFormsConnEdit.Execute(DBConnection, '')
If the user exits shortly after doing this the program crashes with exceptions in TFDPhysMSSQLDriver.GetServers. This is because that function launches a TTask to browse all the available MSSQL servers which takes quite sometime to complete and generates protection errors as soon as it tries to process any "progress" it has made after the rest of the application has shutdown. Since this occurs in the FireDAC library I can't access the ITask handle for the task to wait for it and there doesn't seem to be any obvious way to wait for all outstanding TTasks to complete.
Does anyone know the approved method for either waiting for this task or all tasks to finish or what else I can do to "make safe" before exiting?

How to handle pending connections to a server that is designed to handle a limited number of connections at a time

I wonder what is the best approach to handle the following scenario:
I have a server that is designed to handle only 10 connections at a time, during which the server is busy with interacting with the clients. However, while the the server is busy, there may be new clients who want to connect (as part of the next 10 connections that the server is going to accept). The server should only accept the new connections after it finishes with all previous 10 agents.
Now, I would like to have an automatic way for the pending clients to wait and connect to the server once it becomes available (i.e. finished with the previous 10 clients).
So far, I can think of two approaches: 1. have a file watch on the client side, so that the client will watch for a file written by the server. When the server finishes with 10 clients, it will write the file, and the pending clients will know it's time to connect; 2. make the pending clients try to connect the server every 5 - 10 secs or so until success, and the server will return a message indicating whether it is ready.
Any other suggestion would be much welcome. Thanks.
Of the two options you provide, I am inclined toward the 2nd option of "Pinging" the server. I think it is more complicated to have the server write a file to the client triggering another attempt.
I would think that you should be able to have the client waiting and simply send a READY signal. Keep a running Queue of connection requests (from Socket.Connection.EndPoint, I believe). When one socket completes, accept the next Socket off the queue.

Controlling a long running and critical ISAPI process

Scenario:
Client makes ISAPI call with POST to IIS 7.5 server - the call will generate mission critical output to be distributed to numerous users. (using Delphi XE with Indy 9 HTTP client in this case);
ISAPI process takes a LONG TIME to complete (it's threaded on the client side);
Before the POST call returns, user aborts or client machine goes down, killing client side connection and leaving the ISAPI process chugging away on the IIS 7.5 server.
Questions:
What does IIS 7.5 do with that thread, which is still executing when the client/user aborts and kills the connection?
Will the server side thread complete processing even though the client has disconnected, or will IIS 7.5 kill that thread at some point, perhaps leaving a mess in the aborted process?
Is this time dependent - depending on how long it takes for the server-side process to complete?
Can this be controlled - can I instruct IIS to complete the process even though the client has aborted? If so, how?
IIS will continue to process until completion, or until the timeout for the App Pool is hit.
You should look at using Indy's TIdHTTPServer and then you'll control the server side which will allow you to setup your own rules on how to handle a long and possibly disconnected client session instead of becoming an expert in IIS AppPool management.

running programs without session

I run my programs and want them to go on running although i logged off from the system.
Is there a way to do this without windows services?
Here is what i want:
I remote connect to the server,
I log in to the server,
I start my program.
I log off from the server but my program continues to running...
thanks.
The only solution that I can think of is running your program as a Windows Service .
there is nothing wrong with using a service. You could go to the length of creating a 'server' part of the program that runs as a service and a 'client' gui. But I assume you aren't talking about software you developed, but something else.
The other way would be to use Scheduled Tasks, that would run a program even if user isn't logged in, useful for backup scripts etc.
An alternative would be to write your program, and schedule it to run in the scheduler.
It depends if you want it to run constantly, or not.
I guess you could follow these instructions to configure your program to run as a service. You will set it's "startup type" to manual so that it will not start each time the operating system starts but instead you log in and start the service manually. Then, when you log off, the service continues running.

How to stop a Windows Service programmatically?

I'm writing a simple Windows Service that sends out emails to all employees every month. My question is, how to stop itself when it's done? I'm a noobie in this field so please help me out. Really appreciated.
It will be deployed on the server to be run monthly. I did not start this thing and the code was given to me like that. It is written in VB.NET and I'm asked now to change a few things around it. I noticed that there is only 'Sub OnStart' and wondered when the service would stop? After the main sub is done, what it the status of this service? Is it stopped or just hung in there? Sorry, as I said, I am really new to this....
If you have a task that recurs monthly you may be better off writing a console app, and then using Windows Task Scheduler to set it to run monthly. A service should be used for processes that need to run for a long time or constantly, with or without a user logged on
As every other answer has noted, it sounds like this should be an executable or script that you run as a scheduled task.
However, if you are obligated for some reason to run as a Windows Service and you're working in .NET, you just have to call the Stop() method inherited from ServiceBase once your service completes its work. From the MSDN documentation for the method:
The Stop method sets the service state
to indicate a stop is pending and
calls the OnStop method. After the
application is stopped, the service
state is set to stopped. If the
application is a hosted service, the
application domain is unloaded.
There's one important caveat here: the user account under which the service is running must have permission to stop services (which is a topic for ServerFault).
Once a service's OnStart method completes, it will continue running (doing nothing) until something tells it to stop in one of the following ways:
Programatically, by calling Stop
within the service itself or from an
external process using the method
Colin Gravill describes in his
answer.
Via the command-line.
Through the windows Computer Management console's "Services" panel.
If this is a Win32 service (i.e. written in C or C++), then you simply call SetServiceStatus(SERVICE_STOPPED) and return from ServiceMain.
On the other hand, if you're just sending emails once a month, why are you using a service at all? Use the Windows Task Scheduler and run a normal application or script.
net stop [service_name] ...on the command line will do it too.
But, I agree with everyone else; it seems that Windows Task Scheduler will meet your needs better.
It might be better to write this as a scheduled task, it would certainly be easier to develop initially. Then it would naturally terminate and wouldn't be consuming resources for the rest of the month.
To answer the original question, you can get a list of the current running services in C#
services = System.ServiceProcess.ServiceController.GetServices();
Then look for the one you want and set the status to stopped
locatedService.Status == ServiceControllerStatus.Stopped
Full example on msdn
Is there a reason it has to be a Windows service? If not, then follow #Macros solution. However, if it does, then why stop the service? If you stop it, then it'll just have to be restarted when the emails need to be sent. Based on your description, it doesn't sound like it would require a lot of resources, so I'd suggest just installing it and letting it run, firing up once a month to send the emails.
here's what i did in a similar situation.
windows service runs 24/7 and processes work units. it gets work units through a database view.
table Message
ProcessingStartTime
CompletionDTE
...
the database view only pulls records marked not-complete and have a ProcessingStartTime in the past. So after the service confirms the transaction it executes a stored procedure that updates the database record. For this system, end-user upload excel files to asp.net webfrom that imports them into the database.

Resources