Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# WinForms: Drawing with one or more additional threads. How?

In case I have a big drawing with all kinds of geometric forms (lines, rectangles, circles, e.t.c.) it takes a lot of time for the thread to draw everything. But in real life, one building is built by more than one workers. So if the drawing is the building and the threads are the builders, it will get drawn a lot faster. But I want to know how.

Can you tell me how? Is it even possible (though I have already asked and the answer was "Yes")? Is it worth it to be used? What are the risks?

If there are questions that I have missed, please tell me about them and answer them.

Thanks!

like image 853
AlexSavAlexandrov Avatar asked Sep 27 '11 14:09

AlexSavAlexandrov


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Why is C named so?

Quote from wikipedia: "A successor to the programming language B, C was originally developed at Bell Labs by Dennis Ritchie between 1972 and 1973 to construct utilities running on Unix." The creators want that everyone "see" his language. So he named it "C".


1 Answers

Assuming you are using GDI+ and the System.Drawing.Graphics object to render your graphics (rectangles, circles, etc.) to a background drawing surface (e.g. System.Drawing.Bitmap Object): Instance members of the System.Drawing.Graphics object that you would need to use are not thread safe. See MSDN documentation here

Given this, I would not use more than one "builder" thread to render your graphics.

Instead, my recommendation would be to do all of your drawing to a System.Drawing.Bitmap object in a single background thread rather than multiple background threads if possible. You can use a status bar or other indicator to let the user know that your program is working in the background.

like image 113
bporter Avatar answered Oct 12 '22 07:10

bporter