Q:

Run Next line after application. Run()

My requirement is to get keyspressed when user opens specific URL in chrome. 
For that I am firstly checking for URL opened in chrome after that I am setting hook using below code
    _hookID = SetHook(_proc);
    Application. Run();
    UnhookWindowsHookEx(_hookID);

it is getting the keys on that URL but after that if i close that URL it is continuously getting the keys, that's what i don't want. 
It is because I am calling application.run().  How to run the code after application.run()?  I think that would be the solution 

A:

The call to Aplication. Run is blocking as it starts the Windows Message loop.  That call will return once the main window gets closed and/or one of the messages (for example WM_QUIT) that will end a windows program is being received and handled by the message loop
If you want to run code after the Run method has been called, one option would be to register a handler on the Application. Idle event
_hookID = SetHook(_proc);
Application. Idle += (s,e) => { UnhookWindowsHookEx(_hookID);};
Application. Run();

In my testing the Idle event is raised, once the Run method is called an no other messages are handled by the main message loop. 
Alternatively gracefully exit your windows loop, for example by posting WM_QUIT to its top window.