Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a class named Dot that contains a public method named ShowDot . The method should take no parameters. The class contructor should take a

Create a class named Dot that contains a public method named ShowDot. The method should take no parameters. The class contructor should take a CancellationToken and a ManualResetEvent as parameters and save them into class fields.

The ShowDot method is to be run in a separate thread. The method must ensure that when cancel is signaled in the cancellation token, the thread is interrupted. Then, as long as cancellation is not requested, the thread should repeatedly wait on the manual reset event, write a dot ('.') to the console and then sleep for 1 second. If the thread is interrupted, it should exit (end).

Create a class named Dash that contains a public method named ShowDash. The method should take an object parameter that contains a CancellationToken and a ManualResetEvent (passed using a tuple).

The ShowDash method is to be run in a separate thread. The method must ensure that when cancel is signaled in the cancellation token, the thread is interrupted. Then, as long as cancellation is not requested, the thread should repeatedly wait on the manual reset event, write a dash ('-') to the console and then sleep for 3 seconds. If the thread is interrupted, it should exit (end).

The main application should create a CancellationTokenSource and two ManualResetEvent objects.

Then the main application should create an instance of the Dot class passing the cancellation token and one of the manual reset event objects to the constructor. The application should then create a foreground thread to run the ShowDot method and start it running.

Then the main application should create an instance of the Dash class. The application should then start the ShowDash method running using a thread pool thread and passing the cancellation token and the other manual reset event object to the method.

Once the threads are running, the main application should get a key from the user (use Console.ReadKey so the user does not have to press ENTER). If the user pressed a, the appication should set the dot manual reset event. If the user pressed s, the application should reset the dot manual reset event. If the user pressed z, the application should set the dash manual reset event. If the user pressed x, the application should reset the dash manual reset event. Finally, if the user pressed q, the application should signal cancellation for the threads and exit. The application will continue getting input from the user until q is pressed.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago