Threading seems so complicated, it really isn’t. Today, I’ll provide an example of the simplest thread code you’ve ever seen. In fact, it’s so simple, here it is:
class TheTest { public void Go() { for (int i = 0; i < 100; i++) { WaitCallback wcb = new WaitCallback(this.DoWork); ThreadPool.QueueUserWorkItem(wcb, i); } Console.ReadLine(); } public void DoWork(object state) { int i = (int)state; Console.WriteLine(string.Format("{0:d3} started",i)); Thread.Sleep(500); Console.WriteLine(string.Format("{0:d3} done", i)); } }
Create a new instance of the TheTest class, call go. You’ll see 100 threads get created and do work. You can pass in anything you want for the state. That’s a very good place to put your “unit of work” that the thread must work on. Just make sure you add a using clause for System.Threading.
Of course, this post doesn’t touch on any locking or blocking issues, I’ll do that later. But for now, why not multithread?
Good job
ReplyDeleteNice
ReplyDeleteGreat information on your site here. I love this post because we can get some useful information from your blog. I expect more post from you guys.
ReplyDeletePDO Threads
thread lift
thread face lift
face thread lift
thread lift face
thread lift treatment
thread lift for face
thread lift procedure
non surgical thread face lift
skin threading face lift
neck thread lift
facelift with thread
thread neck lift
threading for face lift
fine thread lifting
thread lift neck
thread nose lift
non surgical facelift threading
thread lift surgery
polydioxanone thread lift
face lifting with threads
facelift by threading
non surgical thread lift
golden thread face lift
face lift thread facelift
nova lift face lift