S
stevek
I've run out of ideas on how to find this bug I've got. I've read up on the
topic and understand that this most likely has something to do with a
threading bug but I can't find it and any attempts to recreate the problem
in a simple and complete application have failed. I've logged the Managed
Thread ID everywhere that I can think of that could be causing the problem
and the IDs are all the same.
"Object is currently in use elsewhere" - what object? From the stacktrace
in my exception it looks like it's definitly the Image instance but I'm not
*positive*.
I know that I should post a working code sample in order to expect any kind
of useful response from the list, but as I mentioned earlier I can't
reproduce in a simple application. I've analyzed the differences between my
real world application and the sample and nothing has stuck out as a clue or
cause. The only thing I can do at this point is explain what my application
is doing as best as I can and include the stack trace.
I would also like to invite anyone that is confident they can identify this
problem via a webex and phone session to contact me. I'd love to pay
someone for an hour of time (or more) to take a look and help me find this
bug.
OK, so I will now try to explain the situation.
**I'm using the Composite Application Block framework for this application.
1. User makes shipping label request by clicking a button on the View (MVP)
2. The Presenter requests an Image from a singleton service method (this
method receives base64 encoded image data and constructs an Image instance
and returns)
3. The singleton service method does some post-processing operations on the
image (removing borders, etc)
4. The presenter then calls a print method on another Singleton object which
prints the image.
Here is the stacktrace:
System.InvalidOperationException: Object is currently in use elsewhere.
at System.Drawing.Image.get_RawFormat()
at System.Drawing.Graphics.IgnoreMetafileErrors(Image image, Int32&
errorStatus)
at System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32
width, Int32 height)
at PMD.Services.PrintingService.document_PrintPage(Object sender,
PrintPageEventArgs e) in C:\PrintingService.cs:line 48
at System.Drawing.Printing.PrintDocument.OnPrintPage(PrintPageEventArgs
e)
at System.Drawing.Printing.PrintDocument._OnPrintPage(PrintPageEventArgs
e)
at System.Drawing.Printing.PrintController.PrintLoop(PrintDocument
document)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at PMD.Services.PrintingService.Print(Image image, String documentName,
String printerName) in C:\PrintingService.cs:line 39
at PMD.ProcessReturnShipmentViewPresenter.Finished() in
C:\ProcessReturnShipmentViewPresenter.cs:line 111
My drawing code is all wrapped in using blocks like so:
private Image PostProcessLabelImage(Image image)
{
// Creating a new copy to try and work around the
// object already in use bug
Image newCopy = new Bitmap(image.Width, image.Height);
// TODO: move this out to the constructor
Rectangle croppedRec = new Rectangle(2, 2, newCopy.Width-4,
newCopy.Height-4);
using (Graphics g = Graphics.FromImage(newCopy))
{
// There is a black border that we want to remove. Paint the
// image to the new DC minus the 2 pixel border
g.DrawImage(image, croppedRec, croppedRec, GraphicsUnit.Pixel);
// Cover up the endicia logo - BS that they even do that,
// should be OUR logo if anything!
g.FillRectangle(Brushes.White, image.Width - 65, 90,
image.Width - 55, 270);
}
return newCopy;
}
Again, guys, I know this bugs you when someone doesn't post a complete
sample. I really have tried to come up with one but haven't been able to.
If you are interested in the gotomeeting approach please contact me ( sklett
[at] pmd direct com ) I can fire up the debugger and step through the code.
-Steve
topic and understand that this most likely has something to do with a
threading bug but I can't find it and any attempts to recreate the problem
in a simple and complete application have failed. I've logged the Managed
Thread ID everywhere that I can think of that could be causing the problem
and the IDs are all the same.
"Object is currently in use elsewhere" - what object? From the stacktrace
in my exception it looks like it's definitly the Image instance but I'm not
*positive*.
I know that I should post a working code sample in order to expect any kind
of useful response from the list, but as I mentioned earlier I can't
reproduce in a simple application. I've analyzed the differences between my
real world application and the sample and nothing has stuck out as a clue or
cause. The only thing I can do at this point is explain what my application
is doing as best as I can and include the stack trace.
I would also like to invite anyone that is confident they can identify this
problem via a webex and phone session to contact me. I'd love to pay
someone for an hour of time (or more) to take a look and help me find this
bug.
OK, so I will now try to explain the situation.
**I'm using the Composite Application Block framework for this application.
1. User makes shipping label request by clicking a button on the View (MVP)
2. The Presenter requests an Image from a singleton service method (this
method receives base64 encoded image data and constructs an Image instance
and returns)
3. The singleton service method does some post-processing operations on the
image (removing borders, etc)
4. The presenter then calls a print method on another Singleton object which
prints the image.
Here is the stacktrace:
System.InvalidOperationException: Object is currently in use elsewhere.
at System.Drawing.Image.get_RawFormat()
at System.Drawing.Graphics.IgnoreMetafileErrors(Image image, Int32&
errorStatus)
at System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32
width, Int32 height)
at PMD.Services.PrintingService.document_PrintPage(Object sender,
PrintPageEventArgs e) in C:\PrintingService.cs:line 48
at System.Drawing.Printing.PrintDocument.OnPrintPage(PrintPageEventArgs
e)
at System.Drawing.Printing.PrintDocument._OnPrintPage(PrintPageEventArgs
e)
at System.Drawing.Printing.PrintController.PrintLoop(PrintDocument
document)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at PMD.Services.PrintingService.Print(Image image, String documentName,
String printerName) in C:\PrintingService.cs:line 39
at PMD.ProcessReturnShipmentViewPresenter.Finished() in
C:\ProcessReturnShipmentViewPresenter.cs:line 111
My drawing code is all wrapped in using blocks like so:
private Image PostProcessLabelImage(Image image)
{
// Creating a new copy to try and work around the
// object already in use bug
Image newCopy = new Bitmap(image.Width, image.Height);
// TODO: move this out to the constructor
Rectangle croppedRec = new Rectangle(2, 2, newCopy.Width-4,
newCopy.Height-4);
using (Graphics g = Graphics.FromImage(newCopy))
{
// There is a black border that we want to remove. Paint the
// image to the new DC minus the 2 pixel border
g.DrawImage(image, croppedRec, croppedRec, GraphicsUnit.Pixel);
// Cover up the endicia logo - BS that they even do that,
// should be OUR logo if anything!
g.FillRectangle(Brushes.White, image.Width - 65, 90,
image.Width - 55, 270);
}
return newCopy;
}
Again, guys, I know this bugs you when someone doesn't post a complete
sample. I really have tried to come up with one but haven't been able to.
If you are interested in the gotomeeting approach please contact me ( sklett
[at] pmd direct com ) I can fire up the debugger and step through the code.
-Steve