Click here to Skip to main content
15,887,683 members
Home / Discussions / C#
   

C#

 
QuestionHow to change background color of RadGridView? Pin
Daniyaltjm28-Aug-16 23:34
Daniyaltjm28-Aug-16 23:34 
AnswerRe: How to change background color of RadGridView? Pin
#realJSOP31-Aug-16 3:26
mve#realJSOP31-Aug-16 3:26 
GeneralRe: How to change background color of RadGridView? Pin
Daniyaltjm31-Aug-16 6:52
Daniyaltjm31-Aug-16 6:52 
Questionhow set custom paper size on printer setting? Pin
Le@rner26-Aug-16 18:34
Le@rner26-Aug-16 18:34 
AnswerRe: how set custom paper size on printer setting? Pin
Richard MacCutchan26-Aug-16 21:01
mveRichard MacCutchan26-Aug-16 21:01 
GeneralRe: how set custom paper size on printer setting? Pin
Le@rner26-Aug-16 21:31
Le@rner26-Aug-16 21:31 
GeneralRe: how set custom paper size on printer setting? Pin
Richard MacCutchan26-Aug-16 21:52
mveRichard MacCutchan26-Aug-16 21:52 
QuestionJoin Main Thread in a Console Application Pin
Member 1270567426-Aug-16 13:25
Member 1270567426-Aug-16 13:25 
I have been looking for a way to detect when the a console application has ended. I want the ability to do some cleanup. Similar to Application.ApplicationExit in forms applications. I've scoured google, code project, msdn, etc. but no solid solution.

I thought about simply launching a cleanup thread at the start of the program and have it Join the main thread. Once that happens perform cleanup. I tried a test application (see code below):

C#
static void Main(string[] args)
{
    Thread cleanupThread = new Thread(cleanupThreadStart);
    cleanupThread.Start(Thread.CurrentThread);
    Thread.Sleep(5000);
    Console.WriteLine("Main: Ended.");
}

private static void cleanupThreadStart(object state)
{
    Thread mainThread = (Thread)state;
    Console.WriteLine("cleanupThreadStart: Waiting for main thread to exit.");
    mainThread.Join();
    Console.WriteLine("cleanupThreadStart: Ended.");
}


Oddly, this solution works from within VS when I start with debugging (F5), meaning that the main thread will end and the cleanup thread will complete the join and I'll see the console printout. However if I start without debugging (ctrl+F5 or simply run the executable directly) the program hangs because the main thread ends but the cleanup thread never completes the Join. I've tried attaching to the process from within VS during the hang and I can see that the main thread is no longer present but the cleanup thread is still waiting for the Join to complete.

Does anybody know why this works with debugging active but not without it? Does anybody have any other clever way of detecting that the application is about to end (similar to Application.ApplicationExit)?

For now I've got a workaround to just create my own "main" thread which executes the normal application code. Then my cleanup thread joins with this thread before cleanup. This seems to work fine.
AnswerRe: Join Main Thread in a Console Application Pin
Garth J Lancaster26-Aug-16 18:36
professionalGarth J Lancaster26-Aug-16 18:36 
AnswerRe: Join Main Thread in a Console Application Pin
Eddy Vluggen29-Aug-16 4:19
professionalEddy Vluggen29-Aug-16 4:19 
Questionreg Pin
mbatra3125-Aug-16 23:01
mbatra3125-Aug-16 23:01 
AnswerRe: How to Parse .XFDL files in C#.? Pin
OriginalGriff25-Aug-16 23:06
mveOriginalGriff25-Aug-16 23:06 
GeneralMessage Closed Pin
25-Aug-16 23:15
mbatra3125-Aug-16 23:15 
GeneralRe: How to Parse .XFDL files in C#.? Pin
OriginalGriff25-Aug-16 23:23
mveOriginalGriff25-Aug-16 23:23 
GeneralRe: How to Parse .XFDL files in C#.? Pin
Richard MacCutchan26-Aug-16 0:06
mveRichard MacCutchan26-Aug-16 0:06 
GeneralRe: How to Parse .XFDL files in C#.? Pin
OriginalGriff26-Aug-16 0:17
mveOriginalGriff26-Aug-16 0:17 
GeneralRe: How to Parse .XFDL files in C#.? Pin
mbatra3111-Oct-17 20:00
mbatra3111-Oct-17 20:00 
GeneralRe: How to Parse .XFDL files in C#.? Pin
OriginalGriff11-Oct-17 20:17
mveOriginalGriff11-Oct-17 20:17 
GeneralRe: How to Parse .XFDL files in C#.? Pin
mbatra3111-Oct-17 20:53
mbatra3111-Oct-17 20:53 
GeneralRe: How to Parse .XFDL files in C#.? Pin
mbatra3111-Oct-17 19:58
mbatra3111-Oct-17 19:58 
GeneralRe: How to Parse .XFDL files in C#.? Pin
Richard MacCutchan11-Oct-17 21:04
mveRichard MacCutchan11-Oct-17 21:04 
QuestiongridView prevent down the line ? Pin
Member 245846725-Aug-16 15:40
Member 245846725-Aug-16 15:40 
AnswerRe: gridView prevent down the line ? Pin
OriginalGriff25-Aug-16 21:43
mveOriginalGriff25-Aug-16 21:43 
Questionmake a call via GSM using c# Pin
maka bregvadze25-Aug-16 1:54
maka bregvadze25-Aug-16 1:54 
AnswerRe: make a call via GSM using c# Pin
Gerry Schmitz25-Aug-16 5:58
mveGerry Schmitz25-Aug-16 5:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.