Force code execute when user closes OOB lightswitch app using the windows close red X

I've created a lightswitch app using Forms Authentication.  If the user closes the application using the window close red 'X', I need to update a custom user profile table.  Is this possible?

I use this code and it works!
I handle the closing event of the user and I break it, execute my code ed after closing the application.
Under you see the code that I use in my application.vb :
Public Class Uscita
' Dichiara un evento per la classe
Public Event Event1()
' Definisce un metodo per richiamare l'evento
Sub CausaEvento()
RaiseEvent Event1()
End Sub
End Class
Protected Sub EsceAPP()
Dim Obj As New Uscita
AddHandler Obj.Event1, AddressOf Me.EventoUscita
' Provoca l'esecuzione dell'evento
Obj.CausaEvento()
End Sub
Sub Eventouscita()
Dispatchers.Main.BeginInvoke(Sub()
RemoveHandler _mainWindowClose.Closing, AddressOf MainWindow_Closing
System.Windows.Application.Current.MainWindow.Close()
End Sub)
End Sub
Private Sub Application_loggedin()
Try
Dispatchers.Main.BeginInvoke(Sub()
_mainWindowClose = System.Windows.Application.Current.MainWindow
AddHandler _mainWindowClose.Closing, AddressOf MainWindow_Closing
End Sub)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub MainWindow_Closing(ByVal sender As Object, ByVal e As ClosingEventArgs)
If MessageBox.Show("Vuoi Veramente uscire?", "Conferma", MessageBoxOption.OkCancel) = Windows.MessageBoxResult.Cancel Then
'Elimina l'uscita utente
e.Cancel = True
Else
'Interrompe momentaneamente l'uscita dell'utente per eseguire l'aggiornamento della tabella utenti loggati
e.Cancel = True
'Aggiorna la tabella utenti loggati ed esce dall'applicativo
Me.Details.Dispatcher.BeginInvoke(Sub()
Dim ws = CreateDataWorkspace()
Dim query = ws.ApplicationData.UtentiLoggatis.Where(Function(c) c.UserName = Me.User.FullName).FirstOrDefault
query.OnLineImage = MyImageHelper.GetImageByName("RedLight.png")
query.OnLIne = "OFF"
query.Logout = Now
ws.ApplicationData.SaveChanges()
'Chiama la routine per uscire dall'applicazione
EsceAPP()
End Sub)
End If
End Sub

Similar Messages

  • Call JavaScript when user closes browser containing webcenter

    Hi
    Scenario:
    1. Webcenter is opened in a browser.
    2. User closes the browser
    Requirement:
    - When user closes browser containing webcenter, a java script (or a servlet) should get called.
    As you know, we can call a script in 'onunload()' of body tag.
    But how do we call it with webcenter?
    Thanks.
    Edited by: 873687 on Dec 14, 2011 5:34 AM

    Here is a few links that I found for the JavaScript side you might play aroudn with.
    http://developer.irt.org/script/1230.htm
    http://www.webreference.com/js/tutorial1/reference.html
    http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20953676.html
    http://www.devguru.com/Technologies/ecmascript/quickref/window.html
    And two in German
    http://www.uni-magdeburg.de/service/www/books/muenz/javascript/objekte/window.htm
    http://www.exine.de/clientseitig/js_work_events.htm

  • Getting exit code 7 when try to install adobe CS5.5 on windows 7 64bit Machine

    Getting exit code 7 when try to install adobe CS5.5 on windows 7 64bit Machine

    Errors "Exit Code: 6," "Exit Code: 7" | CS5, CS5.5
    Mylenium

  • Fellow users, I bought, through app store, the application "Amplitube Slash" but I can't get it working so here's the problem: I do all the connections but when i lunch the app i can't ear nothing and the input says none. Pls help. Best  regards

    Dear users,
    I bought recently the app "Amplitube Slash" for my iPod touch, through the app store and I paid 8€ for it.
    When I tried to play guitar using the application with "Amplitube iRig", I could not listen anything as the input says "none". I would like to know how or if anyone knows how to solve this problem.. You can ask anything if you need more details.
    Best regards
    Duarte

    Here is their support site.
    http://www.ikmultimedia.com/c
    Here is Apple's support article:
    iOS: Troubleshooting applications purchased from the App Storetact-support/

  • My creative CC for teams gives an error code (-60) download corrupted when trying to install any app from the CC on my desktop. Any help?

    My creative CC for teams gives an error code (-60) download corrupted when trying to install any app from the CC on my desktop. Any help?

    Rasco1 it sounds like your managed network needs to be configured to allow you to download successfully.  You can find more details in Error downloading Creative Cloud applications - http://helpx.adobe.com/creative-cloud/kb/error-downloading-cc-apps.html.

  • I have a java code that expires user sessions after 30 min.But the session does not expire in Firefox version 4 where as it expires in all previous versions

    I have a java code that expires user sessions after 30 min.But the session does not expire in Firefox version 4 where as it expires in all previous versions

    A good place to ask questions and advice about web development is at the mozillaZine Web Development/Standards Evangelism forum.<br />
    The helpers at that forum are more knowledgeable about web development issues.<br />
    You need to register at the mozillaZine forum site in order to post at that forum.<br />
    See http://forums.mozillazine.org/viewforum.php?f=25

  • Please advise how I can register my Photoshop Starter Edition when I apply I do not receive an unlock code so I am unable to continue to use the program and all my photos are locked in, please advise, thanks John

    Please advise how I can register my Photoshop Starter Edition when I apply I do not receive an unlock code so I am unable to continue to use the program and all my photos are locked in, please advise, thanks John

    Please refer to the appropriate Forum, this one is dedicated to Photoshop proper.
    Photoshop Album Starter Edition

  • Java daemon on boot: "This user is not allowed access to the window system right now."

    The daemon is located in /Library/LaunchDaemons/ and launches successfully on most occasions. However, it sometimes fails to start with this error:
    Nov 17 20:36:24 server.local java[28972]: This user is not allowed access to the window system right now.
    Nov 17 20:36:24 server com.apple.launchd[1] (net.java.server): Throttling respawn: Will start in 10 seconds
    I have the server command running as a background daemon using its "nogui" option (the developers claim to have written it to not display a gui). However, it seems that somewhere along the line, Java is trying to display something. As the daemon is running before users log in, it gives this error. Once a user is logged in to the system, it runs fine; however, logging in a user to run the server is not an option. It needs to run on boot.
    Any ideas for how to solve this? I'm going to contact the developers to see if it may be something they can fix, but I want to be able to force the issue in case the problem ever occurs in the future.

    Irrespective of any claims by the developer, this certainly appears to be a test case that shows that the tool is not working as expected, and that the application has a bug.  This test case would be better if there was some evidence around why only some of the startups fail, but in general this will involve what's been suggested earlier:  "Contact the application developer."  
    As some general background on what's involved, see daemons and agents and related; processes that are not allowed to connect to the GUI for reasons of security.
    I'd also suggest testing your DNS, as seeing "server.local" can imply local DNS configuration errors.   Launch Terminal.app  from Applications > Utilities and issue the following harmless diagnostic command and see if it reports no changes, or if it detects network or DNS errors:
    sudo changeip -checkhostname
    If this is OS X Server and a NAT'd network, you do not want to reference any DNS servers located off of your NAT'd network.
    Why DNS?  Because DNS errors can cause only some operations to fail, particularly if there's more than one DNS server selected (and where some subset of the DNS servers are malfunctioning or misconfigured).

  • Vista: use the windows program manager to execute operating system commands

    attempting to run forms 6 on vista... the forms app attempts a call sqlplus using the host builtin to populate some tables before calling the report.
    in windows vista i get a message box indicating "use the windows program manager to execute operating system commands".
    is this windwos vista message? would this have to do with permissions?
    any insight most appreciated and thanks in advance.

    I don't know about the HOST-problem, but..
    the forms app attempts a call sqlplus using the host builtin to populate some tables before calling the report.What about putting the logic from the SQL*Plus-scripts into a database-procedure and call that instead. I think,, with the current approach you will get problems at least when you have to migrate to Web (e.g. Forms 10g).

  • When i click on safari to use the internet it says "safari cannot open the page because it is not connected to the internet", but i am connected to a wifi network so how do i get safari to work?

    when i click on safari to use the internet it says "safari cannot open the page because it is not connected to the internet", but i am connected to a wifi network so how do i get safari to work?

    you may be connected to the wireless network but the question is the internet working properly on the wireless network...
    what i mean is that i can make a wireless network without the internet so i can save and share files and have other devices connected to the same network access them... but you have to make sure that your internet it running properly... may have to reconfigure the router is your using PPPOE or if it was working prior to your post then try to restart your modem... that usually resolves most issues.

  • I have iTunes open in Windows XP and get an error 45048 message when I try to update apps thru the store. How can I fix this? I have reinstalled iTunes twice.

    I have iTunes, latest version, open in Windows XP and get an error 45048 message when I try to update apps thru the store. How can I fix this? I have reinstalled iTunes twice but problem continues.

    Try contacting iTunes via email to check if there is an issue with the account. go to apple.com/support/itunes
    Click on iTunes Store account and billing and select inquiries. On the right side click on "email us".
    Before doing that trying viewing your account information first. Open the iTunes on you mac, look at the menu and select store and select view my account. Try removing the card (this is only applicable if you don't have a pending charges with iTunes) and hit done. Sign out, quit iTunes and sign back in and try updating the apps again.

  • Can 2 different users with 2 different Iphones use the same itunes to backup each phone separately? if not how can I have a backup for 2 different iphones on the same laptop?

    can 2 different users with 2 different Iphones use the same itune program to backup each phone separately? if not how can I have a backup for 2 different iphones on the same laptop?

    Here is your answer:
    http://support.apple.com/kb/HT1495

  • How can I create accurate decimal dimensions when creating a new document or using the art board in Illustrator CS6? When I type in a number with a decimal, it automatically rounds the number up.

    How can I create accurate decimal dimensions when creating a new document or using the art board in Illustrator CS6? When I type in a number with a decimal, it automatically rounds the number up.

    For my part you are welcome, sdowers.
    Unfortunately, the uncertainty arising from the rounding has been up several times here in this forum.
    I just came to remember a warning that needs to be given:
    The rounding of the representation of a numerical value may be harmless in itself, but if you use it for any operation that changes the value, such as multiplication or whatever, things will go wrong because the operation will be made on the basis of the rounded value instead of the true value. So, as in your first case in post #2, 39.625 rounded to 39.63 will become 79.26 instead of 79.25.

  • Can you tell me how I can ask for help with the following Indesign question:  I am a new Indesign user and a Creative Cloud member.  I was using the Window/Pages drop down window to view my pages alphabetically or by page number and also to determine whet

    I am a new Indesign user and a Creative Cloud member.  I was using the Window/Pages drop down window to view my pages alphabetically or by page number and also to determine whether or not my JPEG files were sufficiently HI-Res for the printer.  I don't know how I did it but somehow the window has changed so that now it does not have the alphabetical/numerical/Hi-Res information.  It just shows the pages in a two page spread in numerical order.  How can I restore the window so that I will be able to view the information as I did previously.
    Your help will be appreciated,
    Don Unwin
    [Personal Information Removed]

    The pages panel is not the place where you see this information.  You can customize the Links panel to show all sorts of things, including the page number, effective and actual ppi, and whether the link is OK or needs updating.

  • How do I keep the source document open when linking to a target document using the destination option in Adobe X?

    How do I keep the source document open when linking to a target document using the destination option in Adobe X? Have several links to create in the source document and want to keep the source document and target document open at the same time.

    Go to Edit - Preferences - Documents and un-tick "Open cross-document links
    in the same window".

Maybe you are looking for