\"GUI and Multithreading\" Please respond to the following: Describe one (1) way
ID: 3560849 • Letter: #
Question
"GUI and Multithreading" Please respond to the following: Describe one (1) way in which a GUI can take advantage of multiple threads. Provide one (1) example of such advantages to support your response. Imagine that you are tasked with creating software for a banker, who needs to access information for multiple accounts at the same time. Describe one (1) way in which you could combine the paradigms of object-oriented programming and multithreading in order to implement a solution. Support your response with such a combination in action.
Explanation / Answer
Lets take a simple example. Let's assume there is an application that does some sort of time consuming operation on a collection of files, and that it outputs it's progress to the console. Lets assume that this operation takes 2 seconds per file and that there are 10 files to process called 1.txt, 2.txt,3.txt, ... 10.txt. Then an example implementation could look like the following:
console
The console example is of course single threaded and does the job just fine. Now if we wanted to add a graphical progress bar a single threaded implementation might look like the following:
single-threaded gui
This seems to work fine, but as you run the application if you try and interact with the application like try and resize the window for example it will get stuck and only respond every two seconds when it gets freed up to process pending gui events. The final example is a multi-threaded implementation and stays responsive throughout execution.
multi-threaded gui
It seems perfectly clear and logical to me that if you have a long-running blocking operation in your code and you want a responsive gui that you have to use a multi-threaded solution. There is no other way around it. Is this the case? I have tried to explain this many times to fellow developers but many don't understand or don't agree. Can someone provide an explanation of this concept, a link to an article on it, or correct me if my understanding is incorrect.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.