コード例 #1
0
 /// <summary>
 /// UC21 -- Method to add the data records via multithreads
 /// Multithread basically used to ensure maximum utilizaion of cpu resources namely
 /// Thread is an element responsible to execute a piece of code
 /// </summary>
 public void AddingMultipleContactDetailsToAddressBookThreading()
 {
     /// Iterating over bookModels list to add the data records to the databse using the instance of AddressBookModel
     bookModels.ForEach(contactRecord =>
     {
         /// Underneath utilising the ThreadStart delegate to add record to the database
         /// Each iteration is utilising a single thread
         Thread thread = new Thread(() =>
         {
             Console.WriteLine("Record being added" + contactRecord.firstName);
             /// Calling the adder method to insert the record to the address book table
             AddDataToAddressBookDatabaseTable(contactRecord);
             /// Printing the current thread ID
             Console.WriteLine("Current Thread Id is: " + Thread.CurrentThread.ManagedThreadId);
             /// Printing the added record ending message
             Console.WriteLine("Contact added:" + contactRecord.firstName);
         });
         /// Start Method is used to contact the OS regarding the begining of execution of th current thread
         thread.Start();
         /// Join Method is used to ensure that the main thread does not exits before the child threads ends
         thread.Join();
     });
     ///
     bookRepository.GetAllRecords();
 }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("==================================================");
            Console.WriteLine("Welcome to the Address Book Data Retrieval Program");
            Console.WriteLine("==================================================");
            AddressBookRepository repository = new AddressBookRepository();

            repository.EnsureDataBaseConnection();
            Console.ReadKey();
            /// UC1 -- Getting all the records from the address book table
            repository.GetAllRecords();
            /// UC2 -- Insert a record to the address book
            TakeInputOfRecords();
            /// Testing for the success of the insertion to the table
            Console.WriteLine(repository.AddDataToTable(bookModel) ? "Inserted Successfully" : "Insert failed");
            /// UC3 -- Update a record to the address book
            UpdateCall();
            /// UC4 -- Delete a record from the table
            Console.WriteLine(repository.DeleteContactUsingName(null) ? "Deleted Successfully" : "Delete failed");
            /// UC5 -- Get the details of the record of the contacts in the address book of a city or state
            GetByCityOrState();
            /// UC6 -- Get the count of the record of the contacts in the address book of a city or state
            GetCountByParticularCityOrState();
            /// UC7 -- Sort the data by first name for the given city
            SortByName();
            /// UC8 -- Get the count of the contacts stored in a particular contact type
            repository.GetCountOfContactType(1);
            /// UC9 -- Getall the details from the ER - Diagram
            repository.GetAllDataFromTableUsingJoin();
            /// UC10-- Ensuring the other use cases working fine for retrieval
            repository.EnsuringOtherUseCasesForJoinedTable();
            /// UC18 -- Retrieving the data from the address book database entered within a time frame
            repository.RetrieveAllTheContactAddedInBetweenADate(Convert.ToDateTime("2018-01-01"));
            /// UC21 -- Implementing Multithreading concept to the address book problem
            /// Adding multiple data to the address book database using the multiple threads
            MultiThreadingImplementation threadingImplementation = new MultiThreadingImplementation();

            threadingImplementation.AddingMultipleContactDetailsToAddressBookThreading();
        }