Open GoogleCodeExporter opened 8 years ago
I can reproduce the problem with the code you provided. Since TWAIN is quite
tied in
with the Windows messaging system I'm not sure how to fix this. My initial
thoughts are
to create a second hidden window and pass that as the parameter to the
WpfWindowMessageHook.
Original comment by luke.qui...@gmail.com
on 21 Feb 2010 at 11:18
This is the solution that I have found. Sometimes the TestAppWPF application
hangs on "Transferring data" because in some scanners (with old versions of
TWAIN) the windows hook is not released after the process is finished:
Creating a second hidden screen does the trick:
public IScannerChildWindow ScannerChildWindow
{
get { return _scannerChildWindow; }
set
{
_scannerChildWindow = value;
if (_scannerChildWindow != null)
{
// This is a twick to make the TWAIN scanner end the windows hook
// Adding this windows object in this block will ensure that the GC will eliminate it once the TWAIN scanner
// releases the hook
Window windows = new Window()
{
Width = 0,
Height = 0,
WindowStyle = WindowStyle.None,
ShowInTaskbar = false,
ShowActivated = false,
WindowState = WindowState.Minimized
};
windows.Show();
windows.Hide();
_twain = new Twain(new WpfWindowMessageHook(windows));
_twain.TransferImage += delegate(object sender, TransferImageEventArgs args)
{
if (args.Image != null)
{
this.ScannedImages.Add(Imaging.CreateBitmapSourceFromHBitmap(
new System.Drawing.Bitmap(args.Image).GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions()));
}
};
ScannerSourceList = new ObservableCollection<string>(_twain.SourceNames);
if (ScannerSourceList != null && ScannerSourceList.Count > 0)
{
ScannerSourceSelected = ScannerSourceList[0];
}
}
}
}
Original comment by Marzan1...@gmail.com
on 13 Jul 2012 at 12:25
Original issue reported on code.google.com by
baburaj....@gmail.com
on 12 Feb 2010 at 6:53Attachments: