Fixed creating/opening/closing twainsession multiple times in an app not working.

This commit is contained in:
soukoku
2014-08-14 07:34:55 -04:00
parent a8891efe3b
commit f073bc6b65
13 changed files with 147 additions and 53 deletions

View File

@@ -3,6 +3,7 @@ using GalaSoft.MvvmLight.Messaging;
using NTwain;
using NTwain.Data;
using System;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Windows.Media;
@@ -76,12 +77,23 @@ namespace Tester.WPF
var fileSetup = new TWSetupFileXfer
{
Format = wantFormat,
FileName = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.tif")
FileName = GetUniqueName(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test", ".tif")
};
var rc = this.CurrentSource.DGControl.SetupFileXfer.Set(fileSetup);
}
}
private string GetUniqueName(string dir, string name, string ext)
{
var filePath = Path.Combine(dir, name + ext);
int next = 1;
while (File.Exists(filePath))
{
filePath = Path.Combine(dir, string.Format("{0} ({1}){2}", name, next++, ext));
}
return filePath;
}
protected override void OnDataTransferred(DataTransferredEventArgs e)
{
ImageSource img = null;