Vista services: Can show form on invisible desktop? - service

I am attempting to show a form from a service on Vista (using .NET winforms)
Obviously the form would not show to the console user, as services are isolated in session 0.
However the experiment is to see if it is possible to "show" an invisible form and obtain a window handle & message loop
I have tried but when I issue form.Show(), only the form.Load event fires not .Shown or .FormClosing
Is there any way to capture windows messages in this way as a user application would?
I have not attempted to make the service 'interactive' as I do not wish to interact with the logged-on user.

Yes you can show a form on a service's desktop. It will not be shown to any logged in user, in fact in Vista and later OSes you cannot show it to a user even if you set the service to 'interactive'. Since the desktop is not interactive the windows messages the form receives will be slightly different but the vast majority of the events should be triggered the same in a service as they would be on an interactive desktop (I just did a quick test and got the form load, shown, activated and closing events).
One thing to remember is that in order to show a form your thread must be an STA thread and a message loop must be created, either by calling ShowDialog or Applicaton.Run. Also, remember all external interaction with the form will need to be marshaled to the correct thread using Invoke or BeginInvoke on the form instance.
This is certainly very doable but is really not recommended at all. You must be absolutely sure that the form and any components it contains will not show any unexpected UI, such as a message box, under any circumstances. The only time this method can really be justified is when you are working with a dubious quality legacy or 3rd party tool that requires handle creation in order to function properly.

Related

Handle timeout of GNotifications in Gnome?

My program needs to react to the user not taking any action on a GNotification.
More specificially, a piece of data is written to the database only if the user does not press the "undo" button on the notification sent after the data's creation. My target deployment scenario does have notifications enabled and a real timeout value.
To be precise: Moving the notification "away" / deleting it should also count as such a timeout.
1) Is there a built-in way to 'listen' to notification timeouts?
2) If not, how could I still implement similar behavior?
I would use the D-Bus org.freedesktop.Notifications interface. Although it is still a draft specification, it does appear stable. My experience accessing the D-Bus interface using Vala has been that it is easier to use and gives the full feature set of the specification. GNotification doesn't seem to be as feature complete.
From the draft specification you will see there is an expire_timeout argument of the org.freedesktop.Notifications.Notify method. That should fit your time out requirement, although I've not used it personally. There is also a org.freedesktop.Notifications.NotificationClosed signal that will allow your program to be notified when the notification is closed, including because of a time out or if it was dismissed by the user.
This post about the screen lock re-design for GNOME Shell 3.10 might give some indication of what notifications are capable of. The post includes some screenshots of notifications appearing in the lock screen.

What is the correct process to switch between ADFs?

I have a project which lets the user to select from the ADFs existing on a Tango-enabled device, to allow them to correctly localize in a number of different spaces.
My code (Unity 5.5, C#, Farandole SDK) essentially performs manual Tango startup with a null AreaDescription as the entry flow. If the user then selects an ADF, I'm calling TangoApplication.Shutdown() then TangoApplication.Startup(newArea).
in Eisa, this works. In Farandole, I get a permissions failure.
if, using Farandole, I explicitly request permissions (after the Shutdown) and wait for the permissions response to come back before calling Startup, the system appears to re-localise against the new ADF, but the Tango system is re-registering callbacks every time around through Startup without unregistering them, meaning I get my callbacks called multiple times for each ADF that I switch to.
What is the correct process to switch between ADFs? Should a shutdown be required before calling Startup, and if so, what is the correct way to shutdown the TangoApplication to avoid multiple callbacks?
I am interested in this answer too. The way I would do it, is reload the scene with the new ADF, just like it is done in the AreaLearning example, so TangoManager and TangoPoseController are reset.

Eclipse Scout Neon Message box triggered on server side

I am wondering if there is a way to trigger message box on server side.
My case is that I have some logic on server side of the scout application. In the middle of the process some decision need to be made. It this case I would like to trigger message box with YES, NO, CANCEL options.
The way my logic works it really hard to split it into two functions and call one first, ask question and call another with on answer. So this is out of the way for me.
If it is not possible to triggered message box on scout service, is there a way to "mimic" it. So call service method, in the middle pause it, go to client side, present messsage box, return to same service method and continue it.
Why do I need this:
I have dependencies graph (between fields) implemented on scout server side.
After one field has been changed, the whole dependencies graph will be resolved.
One node of the graph has some logic that need user interaction. Problem is that I don't know if this method will be called (dependent on a graph), and if after this method other nods will be called.
You have asked a very similar question few months ago:
Scout Eclipse present optional message on server side
MessageBox is a client concept (package is: org.eclipse.scout.rt.client.ui.messagebox).
You need to transfert the data you need from the server to the client and intercept this information client-side to display the message box you want.
As Jmini already said, MessageBox is a client concept. What you can do is sending back a status (from server to client), checking it on client side and show an appropriate message (box). But then you interrupt your service method and cannot go on where it stopped (alternatively you can throw a VetoException, but this interrupts your service method aswell, so same problem). In my opinion, it is also not a good design to 'request' a user interaction from server side, because in this case, the server side has to wait for the user to respond.
I suggest, if possible, to split your logic into different parts. At first, you execute the first part until you reach the point where you need the user interaction. Then you could save the current state of execution, return to client and show the message. After the user has responded, you should start the 'second' execution, depending on the user's input. This second execution should be started by calling another (new) service, which at first should load or restore the state of the execution saved before requesting the user input.

Why my form go to the top of my screen when my UI freeze?

I have a little issue with a form in a delphy XE2 application:
It's an old issue on this application and i have begin to work on it just since a little time.
When the user choose to launch the process with a button's event, my application launch a connexion with an OPCServer , an SQLServer and construct the form for a good following of data take on the tow servers.
The construction of my form involves a blockage of the interface (for approximately 15 sec) because of lot's of data which are necessary for make it.
When it freeze, if the user want drag the form, she go far away, and usually with the TMainMenu which go out of the screen. After that, it's impossible to use the application because we can't drag and we need to close and re-open.
In the old version, the form be already construct before the connexion. So the modification for a dynamic form isn't in link with this issue.
Life of my event :
-Open connexion with OPC Server
-Open SQL Connexion
-Send SQL Command Text
-FieldByName('') for update my UI (Button.Caption// TPage.TStaticText.Caption // TPage.Label1.Caption)
-FieldByName('') for update an array of record
-Close SQL Connexion
-Open SQL Connexion
-Send SQL CommandText
-FieldByName('') for update an other array of record
-Panel.Visible(false)
-TPage.Panel.Show;
-TPage.Panel.BringToFront;
So I haven't MainForm modification can change its position.
I'm a young developer, so I don't know why it moving and what I can make for repair that...
If you want a part of code, ask me what and i edit this, it's very long and i don't want spam answer.
Thank's for read.
The core of your problem is that you have a lengthy process (form construction) which completely blocks the main thread so your application isn't able to process normal Windows messages at the same time. That is why when you move your application it doesn't properly update its interface.
Now based on your description you already have this form construction process split into multiple steps so you could call Application.ProcessMessages between them.
This will force your application to update its UI part.
But beware calling Application.ProcessMessages often could hurt your application performance quite a bit. Why? It is usually a lengthy process because it forces your application to process all the messages that are in its queue.
Normally not all of these messages get processed as soon as they arrive. Windows groups them in the message queue by their priority list, making sure that high priority messages like WM_PAINT are processed as soon as possible while some other low priority messages like demand for application to respond to OS so that OS can see if the application is still working are mostly processed when application is idle or when they are in queue for certain amount of time.
So that is why Application.ProcessMessages can be so slow as it forces your application to process all messages regardless of their priority.
Also bear in mind that using Application.ProcessMessages can in certain scenarios actually become a bit dangerous.
Let me give you an example:
Lets say that clicking on a button starts a lengthy job which can take some time to finish. Now in order to allow your form to be updated you call Application.ProcessMessages in certain intervals. So far it is all good. But what happens if user clicks on that button again?
Since you are calling Application.ProcessMessages which forces your application to process all the messages and since clicking on button creates a MouseClick message which then fires buttons OnClick event which then executes the OnClick method that has been assigned to buttons OnClick event in the end this will cause the same method that was executed on first button click to be executed again.
So now you have this method partially done from first button click and same method executing again for second mouse click. Now the method that was executed from the second click will finish first and then the method that was started from first button click but was interrupted with Application.ProcessMessages handling the second button click will continue its execution to the end.
This all can lead to strange bugs which are hard to track, because you as a programmer normally don't predict that your end user might have clicked the button twice.
So to avoid this I strongly recommend you implement some safeguard mechanisms to prevent such scenarios by temporarily disabling a button for instance.
But the best solution is always to show your user that your application is working which in most cases will dissuade them from clicking the button again, but unfortunately not always.
You should also take a good care when dynamically constructing a form to enable the controls only after all of the controls have been successfully constructed. Failing to do so the user might click on one of your controls and that control could attempt to access some other control which hasn't yet been created at the time. The result hard to track bug which causes Access Violation.
You might also consider showing a splash screen at start instead of half built form. Why?
For once it is much nicer to see and it tells your users to wait a bit. And for second having main form hidden until it is fully created makes sure that user won't be doing any clicks on it prematurely.

Activity not responding error on emulator when using webservices in json parsing?

Am new to android, am developing application with websevices using json parsing with httpget method,cant use http post method in android actually.
It working fine normally, but many time it shows the error on emulator like activity not responding force close activity.when i put that url in browser it shows the result .but i don't know why this activity not responding error came.
I think the httprequest took more time to retrieve the data from server,but am not sure. any one help me to how to avoid this error or how to minimize this .
I want know what are the possibilities to get this activity not responding error.
Thanks,
Lakshmanan
You need to perform blocking operations such as I/O in a separate thread - see the below linked resource:
http://developer.android.com/guide/practices/design/responsiveness.html:
In Android, the system guards against applications that are insufficiently responsive for a period of time by displaying a dialog to the user, called the Application Not Responding (ANR) dialog, shown at right in Figure 1. The user can choose to let the application continue, but the user won't appreciate having to act on this dialog every time he or she uses your application. It's critical to design responsiveness into your application, so that the system never has cause to display an ANR dialog to the user.
To avoid ANR (Application Not Responding) dialog,
Your business logic code is inside doBackground() of AsyncTask and You may also need to override onPostExecute(),etc. After that it is better to invoke the async task in a Service (bound or normal service).
Service:
(bound service or normal service based on your requirement)
From, android office documentation:
A service is "bound" when an application component binds to it by calling bindService(). A bound service offers a client-server interface that allows components to interact with the service, send requests, get results, and even do so across processes with interprocess communication (IPC). A bound service runs only as long as another application component is bound to it. Multiple components can bind to the service at once, but when all of them unbind, the service is destroyed.