Updated samples to not use sync context as well.

This commit is contained in:
soukoku
2014-05-14 20:13:29 -04:00
parent ee2cbfa5e4
commit 1cd21f86cb
2 changed files with 56 additions and 40 deletions

View File

@@ -58,42 +58,44 @@ namespace Tester.Winform
_twain = new TwainSession(appId);
// either set this and don't worry about threads during events,
// or don't and invoke during the events yourself
_twain.SynchronizationContext = SynchronizationContext.Current;
//_twain.SynchronizationContext = SynchronizationContext.Current;
_twain.StateChanged += (s, e) =>
{
Debug.WriteLine("State changed to " + _twain.State + " on thread " + Thread.CurrentThread.ManagedThreadId);
};
_twain.DataTransferred += (s, e) =>
{
//this.Invoke(new Action(() =>
//{
if (pictureBox1.Image != null)
{
pictureBox1.Image.Dispose();
pictureBox1.Image = null;
}
Bitmap img = null;
if (e.NativeData != IntPtr.Zero)
{
var img = e.NativeData.GetDrawingBitmap();
if (img != null)
pictureBox1.Image = img;
img = e.NativeData.GetDrawingBitmap();
}
else if (!string.IsNullOrEmpty(e.FileDataPath))
{
var img = new Bitmap(e.FileDataPath);
pictureBox1.Image = img;
img = new Bitmap(e.FileDataPath);
}
if (img != null)
{
this.BeginInvoke(new Action(() =>
{
if (pictureBox1.Image != null)
{
pictureBox1.Image.Dispose();
pictureBox1.Image = null;
}
pictureBox1.Image = img;
}));
}
//}));
};
_twain.SourceDisabled += (s, e) =>
{
//this.Invoke(new Action(() =>
//{
btnStopScan.Enabled = false;
btnStartCapture.Enabled = true;
panelOptions.Enabled = true;
LoadSourceCaps();
//}));
this.BeginInvoke(new Action(() =>
{
btnStopScan.Enabled = false;
btnStartCapture.Enabled = true;
panelOptions.Enabled = true;
LoadSourceCaps();
}));
};
_twain.TransferReady += (s, e) =>
{