It sounds to me like whatever is calling DrawCVImageShow
in the first place is Disposing the bitmap immediately after DrawCVImageShow
returns.
If that's the case, there are a couple possiblities:
- Make it so that
DrawCVImageShow
is the one responsible for Disposing the bitmap, not whatever callsDrawCVImageShow
. (Simple solution, though probably not the best from an engineering solution: The thing that created the bitmap should generally be responsible for disposing it, and it makesDrawCVImageShow
a less general method.) - Make a Clone of the bitmap, and dispose that one after it's been used. This is the more proper solution, in my opinion, but it does make things a little bit more complicated. You now need two versions of
DrawCVImageShow
, one that disposes the bitmap (for BeginInvoking), and one that doesn't (the method you have now). This also means you'll have two copies of the bitmap in memory when a BeginInvoke is needed; hopefully these bitmaps are not so large that this is an issue.