Click here to Skip to main content
15,891,184 members
Home / Discussions / C#
   

C#

 
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 
QuestionProgram opening Delay time Pin
rudedog17-Jun-13 4:11
rudedog17-Jun-13 4:11 
AnswerRe: Program opening Delay time Pin
Abhinav S7-Jun-13 7:26
Abhinav S7-Jun-13 7:26 
AnswerRe: Program opening Delay time Pin
Keld Ølykke8-Jun-13 22:45
Keld Ølykke8-Jun-13 22:45 
QuestionImplementing Digital Signature Algorithm with Secure Hash Algorithm (DSAwithSHA1) Pin
Ankur Rawat6-Jun-13 23:08
Ankur Rawat6-Jun-13 23:08 
QuestionRe: Implementing Digital Signature Algorithm with Secure Hash Algorithm (DSAwithSHA1) Pin
Eddy Vluggen6-Jun-13 23:55
professionalEddy Vluggen6-Jun-13 23:55 
AnswerRe: Implementing Digital Signature Algorithm with Secure Hash Algorithm (DSAwithSHA1) Pin
Ankur Rawat9-Jun-13 20:36
Ankur Rawat9-Jun-13 20:36 
GeneralRe: Implementing Digital Signature Algorithm with Secure Hash Algorithm (DSAwithSHA1) Pin
Eddy Vluggen10-Jun-13 2:50
professionalEddy Vluggen10-Jun-13 2:50 
Questionproblem in saving an image in windows application Pin
Arun kumar Gautam6-Jun-13 20:02
Arun kumar Gautam6-Jun-13 20:02 
AnswerRe: problem in saving an image in windows application Pin
Richard MacCutchan6-Jun-13 21:17
mveRichard MacCutchan6-Jun-13 21:17 
GeneralMessage Closed Pin
7-Jun-13 0:46
amit293917-Jun-13 0:46 
GeneralRe: problem in saving an image in windows application Pin
Richard MacCutchan7-Jun-13 1:03
mveRichard MacCutchan7-Jun-13 1:03 
AnswerRe: problem in saving an image in windows application Pin
amit293917-Jun-13 1:10
amit293917-Jun-13 1:10 
QuestionConvert Latitude Longitude To X Y Pixel (C#) Pin
zerozaaa6-Jun-13 18:26
zerozaaa6-Jun-13 18:26 

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.