Does c# have an equivalent of the Java Runnable interface?
If not how could this be implemented or is it simply not needed?
thanks.
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.
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.
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.
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.
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."); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With