Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Threading: does c# have an equivalent of the Java Runnable interface?

Does c# have an equivalent of the Java Runnable interface?

If not how could this be implemented or is it simply not needed?

thanks.

like image 848
DiggerMeUp Avatar asked Dec 17 '09 17:12

DiggerMeUp


People also ask

What do threads do in C?

Thread-based multitasking deals with the concurrent execution of pieces of the same program. A multithreaded program contains two or more parts that can run concurrently. Each part of such a program is called a thread, and each thread defines a separate path of execution.

Is threading possible in C?

Can we write multithreading programs in C? Unlike Java, multithreading is not supported by the language standard. POSIX Threads (or Pthreads) is a POSIX standard for threads. Implementation of pthread is available with gcc compiler.

What is threading and its benefits?

Advantages of Thread Use of threads provides concurrency within a process. Efficient communication. It is more economical to create and context switch threads. Threads allow utilization of multiprocessor architectures to a greater scale and efficiency.

Does C++ have multithreading?

Multithreading support was introduced in C+11. Prior to C++11, we had to use POSIX threads or p threads library in C. While this library did the job the lack of any standard language provided feature-set caused serious portability issues.


1 Answers

Does c# have an equivalent of the Java Runnable interface?

Yes, it's ThreadStart

class Runner {     void SomeMethod()      {         Thread newThread = new Thread(new ThreadStart(Run));         newThread.Start();      }       public void Run()       {           Console.WriteLine("Running in a different thread.")      } } 

Would be equivalent to the following Java code

 class Runner implements Runnable {       void someMethod() {         Thread newThread = new Thread( this );         newThread.start();        }        public void run() {           out.println("Running in a different thread.");       }   } 
like image 83
OscarRyz Avatar answered Sep 24 '22 18:09

OscarRyz