Search Results

Search found 4 results on 1 pages for 'lexrema'.

Page 1/1 | 1 

  • Get close window message in Hidden C# Console Application

    - by LexRema
    Hello everyone. I have a Windows Form that starts some console application in background(CreateNoWindow = rue,WindowStyle = ProcessWindowStyle.Hidden). Windows form gives me opportunity to stop the console application at any time. But I'd like to handle somehow the close message inside the console application. I tried to use hooking like: [DllImport("Kernel32")] public static extern bool SetConsoleCtrlHandler(HandlerRoutine handler, bool add); // A delegate type to be used as the handler routine // for SetConsoleCtrlHandler. public delegate bool HandlerRoutine(CtrlTypes ctrlType); // An enumerated type for the control messages // sent to the handler routine. public enum CtrlTypes { CTRL_C_EVENT = 0, CTRL_BREAK_EVENT, CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT = 5, CTRL_SHUTDOWN_EVENT } private static bool ConsoleCtrlCheck(CtrlTypes ctrlType) { StaticLogger.Instance.DebugFormat("Main: ConsoleCtrlCheck: Got event {0}.", ctrlType); if (ctrlType == CtrlTypes.CTRL_CLOSE_EVENT) { // Handle close stuff } return true; } static int Main(string[] args) { // Subscribing HandlerRoutine hr = new HandlerRoutine(ConsoleCtrlCheck); SetConsoleCtrlHandler(hr, true); // Doing stuff } but I get the message inside ConsoleCtrlCheck only if the console window is created. But if window is hidden - I don't get any message. In my windows Form to close console application process I use proc.CloseMainWindow(); to send message to the console window. P.S. AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; - also does not help Do you now other way to handle this situation? Thanks.

    Read the article

  • SELECT table name that is inside UNION

    - by LexRema
    I have two same tables. I need to union them in such way: SELECT f1,f2, xxx FROM (SELECT * FROM tbl1 UNION ALL SELECT * FROM tbl2) where xxx would query for a table name, where f1 and f2 fields are taken from. Example output: 123 345 'tbl1' -- this rows are from the first table 121 345 'tbl1' 121 345 'tbl1' 123 345 'tbl1' 124 345 'tbl1' 125 345 'tbl2' -- this rows are from the second table 127 345 'tbl2' Thank you in advance.

    Read the article

1