Click here to Skip to main content
15,922,325 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to deal with environment variables and non admin users Pin
bfis1081379-Jun-13 20:25
bfis1081379-Jun-13 20:25 
GeneralRe: How to deal with environment variables and non admin users Pin
Dave Kreskowiak10-Jun-13 1:21
mveDave Kreskowiak10-Jun-13 1:21 
QuestionCrystal report login popsup why? Pin
zakirox1238-Jun-13 20:52
zakirox1238-Jun-13 20:52 
AnswerRe: Crystal report login popsup why? Pin
OriginalGriff8-Jun-13 21:59
mveOriginalGriff8-Jun-13 21:59 
GeneralRe: Crystal report login popsup why? Pin
zakirox1238-Jun-13 22:20
zakirox1238-Jun-13 22:20 
AnswerRe: Crystal report login popsup why? Pin
Abhinav S9-Jun-13 5:18
Abhinav S9-Jun-13 5:18 
QuestionSAD_1969_UTM_Zone_23S to WGS84 Coordinate convertion using C# Pin
pvt_infotech7-Jun-13 22:57
pvt_infotech7-Jun-13 22:57 
AnswerRe: SAD_1969_UTM_Zone_23S to WGS84 Coordinate convertion using C# Pin
Bernhard Hiller11-Jun-13 0:05
Bernhard Hiller11-Jun-13 0:05 
QuestionHow to sort serial no in datagridview ,c# Pin
Member 30804707-Jun-13 21:34
Member 30804707-Jun-13 21:34 
AnswerRe: How to sort serial no in datagridview ,c# Pin
Abhinav S7-Jun-13 21:40
Abhinav S7-Jun-13 21:40 
QuestionHow to use product key in my windows application. Pin
ajjuvirgo7-Jun-13 20:04
ajjuvirgo7-Jun-13 20:04 
AnswerRe: How to use product key in my windows application. Pin
Abhinav S7-Jun-13 20:50
Abhinav S7-Jun-13 20:50 
QuestionHow to validate a text box in windows form application using c#. Pin
ajjuvirgo7-Jun-13 20:03
ajjuvirgo7-Jun-13 20:03 
AnswerRe: How to validate a text box in windows form application using c#. Pin
OriginalGriff7-Jun-13 20:18
mveOriginalGriff7-Jun-13 20:18 
AnswerRe: How to validate a text box in windows form application using c#. Pin
Abhinav S7-Jun-13 20:51
Abhinav S7-Jun-13 20:51 
QuestionDoes C# have similar interrupts as embedded C Pin
Member 100880257-Jun-13 13:41
Member 100880257-Jun-13 13:41 
AnswerRe: Does C# have similar interrupts as embedded C Pin
Dave Kreskowiak7-Jun-13 14:02
mveDave Kreskowiak7-Jun-13 14:02 
GeneralRe: Does C# have similar interrupts as embedded C Pin
Member 100880257-Jun-13 16:36
Member 100880257-Jun-13 16:36 
AnswerRe: Does C# have similar interrupts as embedded C Pin
Garth J Lancaster7-Jun-13 14:53
professionalGarth J Lancaster7-Jun-13 14:53 
GeneralRe: Does C# have similar interrupts as embedded C Pin
Member 100880257-Jun-13 16:36
Member 100880257-Jun-13 16:36 
AnswerRe: Does C# have similar interrupts as embedded C Pin
OriginalGriff7-Jun-13 20:30
mveOriginalGriff7-Jun-13 20:30 
To add to what Dave and Garth have said, No, but more "no-ish" than an absolute "NO".

If you are using a console app, then it's not simple, but it is possible. If you are writing a WinForms app then it's pretty simple.

In both cases it is a case of moving the "progam" you want to "interrupt" into a separate thread (look at the BackgroundWorker class) and handling input on the normal thread. When anything (such as a keyboard event) happens, it is processed on the main thread not the "program" thread.
C#
static void Main(string[] args)
    {
    Console.WriteLine("Hello World!");
    BackgroundWorker work = new BackgroundWorker();
    work.DoWork += new DoWorkEventHandler(work_DoWork);
    work.RunWorkerAsync();
    if (Console.ReadLine() == "")
        {
        Console.WriteLine("Aborted");
        }
    }

static void work_DoWork(object sender, DoWorkEventArgs e)
    {
    int i = 0;
    while (i < 100)
        {
        Thread.Sleep(500);
        Console.WriteLine(i++);
        }
    }
Try that, you'll see what I mean!
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

GeneralRe: Does C# have similar interrupts as embedded C Pin
Dave Kreskowiak8-Jun-13 3:35
mveDave Kreskowiak8-Jun-13 3:35 
GeneralRe: Does C# have similar interrupts as embedded C Pin
OriginalGriff8-Jun-13 3:54
mveOriginalGriff8-Jun-13 3:54 
AnswerRe: Does C# have similar interrupts as embedded C Pin
RichardGrimmer10-Jun-13 5:17
RichardGrimmer10-Jun-13 5:17 
AnswerRe: Does C# have similar interrupts as embedded C Pin
jschell10-Jun-13 9:20
jschell10-Jun-13 9:20 

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.