C# FAQ: What is the difference between CSharp and Java threads

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
CSharp-Online.NET:FAQs
edit

What is the difference between C# and Java threads?

A thread is a non-deterministic, execution sequence—flow of control—within a process or program. Multiple threads can execute concurrently, possibly running independently of each other or sharing data. The advantages of threaded programming include—in GUI applications—avoiding GUI freeze by executing a background thread, reducing total execution time—by executing other threads while threads are blocked, e.g. as when performing I/O—, and taking advantage of multiprocessor architecture parallelism.

Whereas a Java method is designed specifically to run in a multithreaded context, any C# method can be executed in a multithreaded context.

Java threads can be created either by implementing the java.lang.Runnable interface or by subclassing the java.lang.Thread class and by overriding the run() method.

C# threads are created by instantiating System.Threading.Thread and passing a System.Threading.ThreadStart delegate to it. The delegate has been initialized with the desired method to be run as a thread.

Every Java class inherits the notify(), notifyAll(), and wait() thread methods of java.lang.Object. The analogous C# methods are the Pulse(), PulseAll(), and Wait() methods of System.Threading.Monitor.

See also



Personal tools