Threading using Cand 线程使用C #和.Net Old Dominion University.pptVIP

  • 0
  • 0
  • 约6.85千字
  • 约 18页
  • 2017-03-09 发布于上海
  • 举报

Threading using Cand 线程使用C #和.Net Old Dominion University.ppt

Threading using Cand 线程使用C #和.Net Old Dominion University

* Calls to Exit are enclosed in finally blocks to ensure that they’re executed even when an exception arises. Otherwise it may lead a thread to acquire lock indefinitely and causes other threads to hang. * Finally block is there but can’t be seen. It is automatically generated in the CIL statements. * AcquireReaderLock blocks if the lock is currently owned by a writer thread but not if it’s owned by other reader threads. AcquireWriterLock blocks if the lock is owned by any one. Consequently multiple threads can read the resource concurrently , but only one thread at a time can write to it and it can’t wait if another thread is reading. * * * * * Threading using C# and .Net cs795 Satish Lakkoju Outline : Threads System.Threading Namespace . Thread Class – its methods and properties. Thread Synchronization. Monitors C# Lock keyword. Reader/Writer Locks Conclusion Threads : Thread is the fundamental unit of execution. More than one thread can be executing code inside the same process (application). On a single-processor machine, the operating system is switching rapidly between the threads, giving the appearance of simultaneous execution. With threads you can : Maintain a responsive user interface while background tasks are executing Distinguish tasks of varying priority Perform operations that consume a large amount of time without stopping the rest of the application System.Threading Namespace Provides classes and interfaces that enable multithreaded programming. Consists of classes for synchronizing thread activities . Chief among the namespace members is Thread class Thread Class Implements various methods properties that allows to manipulate concurrently running threads. Some of them are : CurrentThread IsAlive IsBackground Name Priority ThreadState Starting a thread : Thread thread = new Thread(new ThreadStart (ThreadFunc)); //Creates a thread object // ThreadStart identifies the method that the thread executes when it

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档