What good is Runnable?

Asked

Viewed 188 times

0

I was thinking of creating thread one in my software, but I saw through the forums that the Runnable help in a certain way in creating a thread, and wanted to understand how it works.

1 answer

4


I don’t know anything about Runnable in C#, this is a Java thing. This class was required by a deficiency at the beginning of the language.

Even the use of thread is considered outdated in C#. Of course it can be used, but the ideal, whenever possible, that is adequate, and almost always is, prefer to use Task, which will choose to create/use threads internal if necessary.

If you want to insist on it, take a look at ThreadStart.

  • In fact, what is this Runnable and why we don’t have in C#?

  • Probably because you don’t have to, you have better mechanisms.

  • Runnable is an interface that forces to implement a method without parameters that does not return anything, this method by chance is called run() and contains the code to be effectively executed by the thread, so it is passed to the class Thread trigger thread execution on the operating system. For convenience the Thread class also implements the Runnable interface and can itself contain the code in question (actually a subclass of it).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.