Click to See Complete Forum and Search --> : how to perform Drawing in a thread?
Andy Tacker
August 4th, 2003, 07:13 AM
Hi!
another question!
how to hang the OnPaint event into a thread?
i had tried using delegate but didnt give that result which was desired...
any ideas?
MartinL
August 4th, 2003, 09:19 AM
1.) please, write more descriptive subject to the post...
2.) I don't think that painting in the different thread is good idea.
There are many points why it should be done in the primary thread. There is Graphics object passed into the Paint handler. You don't know what framework does with that object after the handler finishes. That object contains for example Handle (Win32 HWND) of the painting area. I am pretty sure that the framework releases this handle after you leave you paint handler. The second issue you have to take into account is that paint handler is invoked everytime when the window needs to be painted. So your approach can result in unpredictible number of thread painting into big amount if Graphics object. That can be a big problem.
I suppose the painting routine takes really long time if you want to move it into the different thread.
I would solve this by creating different thread wich will prepare the information for paint handler. Which will for example generate bitmap and everytime when paint handler is invoked it just draws that bitmap.
Martin
Andy Tacker
August 4th, 2003, 09:49 AM
1.) am Sorry for subject briefness, I have changed it :)
2.) i agreee with you regarding the issues you have mentioned. so, lemme give you a brief idea.
I have a Map Server, which provides me Map Pictures, say bitmap, for some particular coordinates. now, i get GPS coordinates from different places, say a moving vehicle.
I have to draw these coordinates to represent the movement trajectory of the vehicle. i am using a collection class which holds all those coordniates, and then I am using general painteventargs and creating rectangle and drawing lines between them.
so, this gives pretty good result but the REDRAWING of the whole object take a lot of time. it gives a LAG which is simply unwanted for a commercial project.
so, All I am looking for is some roundabout to draw those coordinates without using much of the OnPaint Event.
tomcat101
August 5th, 2003, 10:12 AM
hi,
just a question: can you use the double buffering for the painting or do you use it already?
example: ("this" is the form where the picture is painted)
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint , true);
this.SetStyle(ControlStyles.UserPaint, true);
hope it helps
blue skies
Andy Tacker
August 6th, 2003, 01:12 AM
Tom that's all been done.
none helps...
Originally posted by tomcat101
hi,
just a question: can you use the double buffering for the painting or do you use it already?
example: ("this" is the form where the picture is painted)
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint , true);
this.SetStyle(ControlStyles.UserPaint, true);
hope it helps
blue skies
Andy Tacker
August 6th, 2003, 01:18 AM
so, after trying delegates and even a separate drawing thread. I couldn't get the desired result.
what I got was that coordinates were drawn. But if the control is painted or refreshed, they were lost.
Starting the thread when OnPaint Event is fired, is rather not a good idea.
so, I think i better be giving it up :)
anywayz if someone got something better to think about , please do share.
MartinL
August 6th, 2003, 03:05 AM
Just an idea. I have never done it using .NET and even don't know how to do it in GDI+. However using standart GDI I would do something as follows:
I would start a thread (outside of WM_PAINT handler). In that thread I would create memory DC and I would paint all the stuff inside this DC. When the painting into that DC is done I would use another memory DC to paint updated stuff. It means I would use 2 memory DC. One of it hold actual image.
Everytime when WM_PAINT handler is invoked I would just check which of that two DCs holds complete image and the use BitBlt function to copy content of that memory DC to the window DC.
It means that WM_PAINT handler will be really guick and all real painting will be perfomed in another thread.
Try to think is this could solve your situation. Probably there is a method how to implement it using GDI+. If it is not, you can still use InteropServices and use classical GDI to this task.
Again, just an idea...
martin
tomcat101
August 6th, 2003, 03:20 AM
another idea
may i ask, do you use the maps as background-image on your view?
i had a similar problem in a simulation programm where i too needed a image on the whole view and over the image there had to be all the simulation-controls and the whole view was updated in relation with a timer every 200 miliseconds.
it didn't work since i took the image and painted it as background image of my sim-view but then there was no more flickering anyway if there was one control or fifthy of them.
but i have to say this image was not so large ( filesize about 10 megabytes ) so i guess there is a lot more on a map like you have.
blue ones
Andy Tacker
August 6th, 2003, 04:52 AM
yeah Martin. I had tried to use GDI+.
as Tom says. what we have here is a MAP object. well, no worries what is the object. basically it is a Bitmap. i have a picture box, where this bitmap is displayed. now, I draw those coordinates there. so, basically, nothing is wrong.
I tried Delegate and use GDI in there. but no luck. the coordinates are drawn but on every pain event they are redrawn.
another option is to draw these coordinates and store the image :) and show, draw and save new image and on and on... but that will be like a wwoooo dunno know what :))...
so, that's the problem.
well, thanks for your replies.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.