• 大小: 19.38MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-07-08
  • 语言: C#
  • 标签: thread  

资源简介

C#线程参考手册 pdf 照书上打的代码。部分可用 C#线程参考手册 pdf 照书上打的代码。部分可用 C#线程参考手册 pdf 照书上打的代码。部分可用

资源截图

代码片段和文件信息

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace BookLib
{
    internal interface IBookCollection
    {
        void Clear();
        void Add(Book n);
        Book GetBook(string ISBN);
        bool IsSynchronized { get; }
        object SyncRoot { get; }

    }

    public class Book
    {
        public string Name;
        public string ISBN;
        public string Author;
        public string Publisher;
    }

     class BookLib : IBookCollection
     {
         internal Hashtable bk = new Hashtable(10);
         public virtual void Clear()
         {
             this.bk.Clear();
         }

         public virtual void Add(Book n)
         {
             Console.WriteLine(“adding book for threadid: “ + Thread.CurrentThread.GetHashCode() + “ ISBN“ + n.ISBN);
             Thread.Sleep(2000);
             bk.Add(n.ISBN n);
         }

         public virtual Book GetBook(string ISBN)
         {
             Console.WriteLine(“getting book for threadid: “ + Thread.CurrentThread.GetHashCode());
             return (Book) bk[ISBN];
         }

         public virtual bool IsSynchronized
         {
             get { return (false); }
         }

         public virtual object SyncRoot
         {
             get { return (this); }
         }

         public BookLib Synchronized()
         {
             return Synchronized(this);
         }
         public static BookLib Synchronized(BookLib bc)
         {
             if (bc == null)
             {
                 throw new ArgumentNullException(“bc“);
             }
             if (bc.GetType() == typeof (SyncBookLib))
             {
                 throw new InvalidOperationException(“BookLib reference is already synchronized.“);
             }
             return new SyncBookLib(bc);
         }
         public static IBookCollection Synchronized(IBookCollection acc)
         {
             if (acc == null)
             {
                 throw new ArgumentNullException(“acc“);
             }
             if (acc.GetType() == typeof(SyncBookLib))
             {
                 throw new InvalidOperationException(“BookLib reference is already synchronized.“);
             }
             return new SyncBookLib(acc);
         }
     }

    internal sealed class SyncBookLib : BookLib
    {
        private object syncRoot;
        private object booklib;

        internal SyncBookLib(IBookCollection acc)
        {
            booklib = acc;
            syncRoot = acc.SyncRoot;
        }

        public override void Clear()
        {
            lock (syncRoot)
            {
                base.Clear();
            }
        }

        public override void Add(Book n)
        {
            lock (syncRoot)
            {
                base.Add(n);
      

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件    6286308  2016-04-13 14:02  thread\C#线程参考手册.pdf

     文件        187  2016-03-31 15:33  thread\code\BookLib\App.config

     文件       8192  2016-03-31 17:14  thread\code\BookLib\bin\Debug\BookLib.exe

     文件        187  2016-03-31 15:33  thread\code\BookLib\bin\Debug\BookLib.exe.config

     文件      19968  2016-03-31 17:14  thread\code\BookLib\bin\Debug\BookLib.pdb

     文件      23168  2016-03-31 17:14  thread\code\BookLib\bin\Debug\BookLib.vshost.exe

     文件        187  2016-03-31 15:33  thread\code\BookLib\bin\Debug\BookLib.vshost.exe.config

     文件        490  2013-03-18 17:00  thread\code\BookLib\bin\Debug\BookLib.vshost.exe.manifest

     文件       2556  2016-03-31 15:33  thread\code\BookLib\BookLib.csproj

     文件        247  2016-03-31 17:14  thread\code\BookLib\obj\Debug\BookLib.csproj.FileListAbsolute.txt

     文件       8192  2016-03-31 17:14  thread\code\BookLib\obj\Debug\BookLib.exe

     文件      19968  2016-03-31 17:14  thread\code\BookLib\obj\Debug\BookLib.pdb

     文件        725  2016-04-08 16:40  thread\code\BookLib\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6589  2016-04-13 14:58  thread\code\BookLib\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件          0  2016-03-31 15:33  thread\code\BookLib\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2016-03-31 15:33  thread\code\BookLib\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2016-03-31 15:33  thread\code\BookLib\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件       4934  2016-03-31 17:14  thread\code\BookLib\Program.cs

     文件       1356  2016-03-31 15:33  thread\code\BookLib\Properties\AssemblyInfo.cs

     文件        187  2016-04-01 14:25  thread\code\Calculate\App.config

     文件       6656  2016-04-05 16:44  thread\code\Calculate\bin\Debug\Calculate.exe

     文件        187  2016-04-01 14:25  thread\code\Calculate\bin\Debug\Calculate.exe.config

     文件      17920  2016-04-05 16:44  thread\code\Calculate\bin\Debug\Calculate.pdb

     文件      23168  2016-04-06 11:20  thread\code\Calculate\bin\Debug\Calculate.vshost.exe

     文件        187  2016-04-01 14:25  thread\code\Calculate\bin\Debug\Calculate.vshost.exe.config

     文件        490  2013-03-18 17:00  thread\code\Calculate\bin\Debug\Calculate.vshost.exe.manifest

     文件       2560  2016-04-01 14:25  thread\code\Calculate\Calculate.csproj

     文件        352  2016-04-06 11:20  thread\code\Calculate\obj\Debug\Calculate.csproj.FileListAbsolute.txt

     文件       1755  2016-04-05 16:17  thread\code\Calculate\obj\Debug\Calculate.csprojResolveAssemblyReference.cache

     文件       6656  2016-04-05 16:44  thread\code\Calculate\obj\Debug\Calculate.exe

............此处省略1291个文件信息

评论

共有 条评论