Looping a function while running a program

  • Thread starter Thread starter Stan.Loughmiller
  • Start date Start date
S

Stan.Loughmiller

I am trying to get a function to loop in C# while allowing the rest of
the program to run. The function is a boolean that constantly checks
the state of a switch while a program is run. If the switch is
activated then the program is stopped and a new program is started. Is
this possible in C#, if so, where do I start.
Thanks,
Stan
 
I am trying to get a function to loop in C# while allowing the rest of
the program to run. The function is a boolean that constantly checks
the state of a switch while a program is run. If the switch is
activated then the program is stopped and a new program is started. Is
this possible in C#, if so, where do I start.
Thanks,
Stan

Something like: (ish!)


class MyClass
{
Boolean myBool = false;

private void Main()
{
Thread CheckingThread = new Thread(new Thread(CheckFunc));
CheckingThread.Start();

//Do other stuff

if (myBool == true) DoSomethingElse();
}

Private void (CheckingFunc)
{
if (Something == true) myBool = true;
}
}
 
I'll give this a try and see what happens. Thanks for the help.
 
The Thread class and what not are part of the System.Threading
namespace by the way.

Definately get familiar with that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top