   BitBlt bug....
  Hey guys!I am making a 2d map editor but I am having some problems with BitBlt, I have my own Paint method being called in my own Canvas usercontrol which I have created, it draws everything I want it to by looping through my "map" array and drawing it inside the canvas viewable on screen, but for some reason if I make any modifications to that array, such as changing one of the ties that will be displayed and then either calling Refresh() or Invalidate(), it will draw the first tile change to the canvas but if I make any further alterations to the array( by clicking on the canvas image again with another new tile) and calling a Refresh again it just crashes and wont allow any more changes?I really dont understand how I can do it once but no more times? my code is below if anyone can help me? I have just provided the code for the Canvas bitblt stuff as the code for the array changes is a bit ott on the maths :)P.S. I am using C#m_pImage = parent.getMapReader().getCanvasImage().GetHbitmap();IntPtr target = e.Graphics.GetHdc();IntPtr source = Win32.CreateCompatibleDC(target);int tileCount = 0;for (int index = 0; index < parent.getMapReader().getMapInput().Count; index++){  for (int j = 0; j < parent.getMapReader().getMapInput()[index].Length / 2; j++)  {    Win32.SelectObject(source, m_pImage);    Win32.BitBlt(target, j * 16, index * 16, 16, 16, source, parent.getMapReader().getMultiDimen()[tileCount].getX() * 16, parent.getMapReader().getMultiDimen()[tileCount].getY() * 16, TernaryRasterOperations.SRCCOPY);    tileCount++;  }}Win32.DeleteDC(source);e.Graphics.ReleaseHdc(target);Thanks loads in advance!   
  I've never used C#, but in C++ with the windows GDI, it is not a good idea to create and delete your "source" DC every frame, create it at initialization, then delete it when you shutdown.  This may or may not fix your problem.   ;  Hey, unfortunately I dont see how I can do this as the tile sheet I am using can be changed by the user at any point so I need to ensure that the source is being made before the drawing which would mean more than one call. Also in order to get the Source I need to use the PaintEventArgs from the method: void PaintMap(object sender, PaintEventArgs e){  IntPtr target = e.Graphics.GetHdc();  IntPtr source = Win32.CreateCompatibleDC(target);}otherwise I cant get hold of the PaintEventArgs Graphics.I have finally managed to get a proper error to come up regarding this problem it is:InvalidOperationException was unhandled:Object is currently in use elsewhereThis occurs when I try to use Refresh(); on the Canvas on the 2nd time I change or try to change a tile, the first time it changes perfectly fine.Any help guys? starting to get me down :(   ;  Hey guys!Figured it out, my Bitblt code was not the problem, the problem was passing in an array in the end, sorry for wasting anyones time.works perfectly now :)   