mirror of
https://github.com/soukoku/ntwain.git
synced 2025-10-26 03:32:00 +08:00
tester crashes on close if twain not initialized.
This commit is contained in:
@@ -41,13 +41,16 @@ namespace Tester.Winform
|
|||||||
|
|
||||||
protected override void OnFormClosing(FormClosingEventArgs e)
|
protected override void OnFormClosing(FormClosingEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.CloseReason == CloseReason.UserClosing && _twain.State > 4)
|
if (_twain != null)
|
||||||
{
|
{
|
||||||
e.Cancel = true;
|
if (e.CloseReason == CloseReason.UserClosing && _twain.State > 4)
|
||||||
}
|
{
|
||||||
else
|
e.Cancel = true;
|
||||||
{
|
}
|
||||||
CleanupTwain();
|
else
|
||||||
|
{
|
||||||
|
CleanupTwain();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
base.OnFormClosing(e);
|
base.OnFormClosing(e);
|
||||||
}
|
}
|
||||||
@@ -105,22 +108,19 @@ namespace Tester.Winform
|
|||||||
|
|
||||||
private void CleanupTwain()
|
private void CleanupTwain()
|
||||||
{
|
{
|
||||||
if (_twain != null)
|
if (_twain.State == 4)
|
||||||
{
|
{
|
||||||
if (_twain.State == 4)
|
_twain.CurrentSource.Close();
|
||||||
{
|
}
|
||||||
_twain.CurrentSource.Close();
|
if (_twain.State == 3)
|
||||||
}
|
{
|
||||||
if (_twain.State == 3)
|
_twain.Close();
|
||||||
{
|
}
|
||||||
_twain.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_twain.State > 2)
|
if (_twain.State > 2)
|
||||||
{
|
{
|
||||||
// normal close down didn't work, do hard kill
|
// normal close down didn't work, do hard kill
|
||||||
_twain.ForceStepDown(2);
|
_twain.ForceStepDown(2);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user