I need a little confirmation over something I am confused at. I know how threads work in java:
new DialList(string a , string b).start(); // where DialList is a class
public class DialList extends Thread {
public DialList(String a, string b) {
FilePath = a;
ThreadLogFile = b";
}
public void run() {
// some code to run in different thread
}
}
Now I want to run the same code in C#. Shall I put the code which is in run() into a method and do something like:
Thread t = new Thread (runcsharp); // Kick off a new thread
t.Start();
static void runcsharp(parameters) {
// code
}
or is there some other way to do it?
There are a few different ways to start a new thread in C#. For example:
Note that this assumes that
WriteYhas no parameters. If it did, you would have to use the ParameterizedThreadStart delegate.For detailed information, see Joe Albahari’s excellent (and free) ebook.
edit: if I understand this correctly, you have an object of type
DialListthat you want to pass to a new thread. You can do that in C# this way: