Added musings on runnig as Console app.

This commit is contained in:
soukoku
2014-04-06 15:22:11 -04:00
parent 0bd58e5e48
commit 006d33b451
7 changed files with 272 additions and 5 deletions

50
NTwain/AsyncPump.cs Normal file
View File

@@ -0,0 +1,50 @@
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading;
//using System.Windows.Threading;
//namespace NTwain
//{
// // from http://blogs.msdn.com/b/pfxteam/archive/2012/01/20/10259049.aspx
// /// <summary>
// /// Provides a pump that supports running asynchronous methods on the current thread.
// /// </summary>
// public static class AsyncPump
// {
// /// <summary>
// /// Runs the specified asynchronous function.
// /// </summary>
// /// <param name="func">The asynchronous function to execute.</param>
// /// <exception cref="System.ArgumentNullException">func</exception>
// /// <exception cref="System.InvalidOperationException">No task provided.</exception>
// public static void Run(Func<Task> func)
// {
// if (func == null) throw new ArgumentNullException("func");
// var prevCtx = SynchronizationContext.Current;
// try
// {
// var syncCtx = new DispatcherSynchronizationContext();
// SynchronizationContext.SetSynchronizationContext(syncCtx);
// var t = func();
// if (t == null) throw new InvalidOperationException();
// var frame = new DispatcherFrame();
// t.ContinueWith(_ => { frame.Continue = false; },
// TaskScheduler.Default);
// Dispatcher.PushFrame(frame);
// t.GetAwaiter().GetResult();
// }
// finally
// {
// SynchronizationContext.SetSynchronizationContext(prevCtx);
// }
// }
// }
//}

View File

@@ -53,6 +53,7 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="AsyncPump.cs" />
<Compile Include="Data\TypesExtended.cs" />
<Compile Include="DeviceEventArgs.cs" />
<Compile Include="Extensions.cs" />

View File

@@ -309,10 +309,7 @@ namespace NTwain
/// <exception cref="ArgumentNullException">context</exception>
public ReturnCode EnableSource(SourceEnableMode mode, bool modal, HandleRef windowHandle, SynchronizationContext context)
{
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
if (context == null) { throw new ArgumentNullException("context"); }
}
if (context == null) { throw new ArgumentNullException("context"); }
Debug.WriteLine(string.Format("Thread {0}: EnableSource.", Thread.CurrentThread.ManagedThreadId));
@@ -378,6 +375,8 @@ namespace NTwain
/// <summary>
/// Forces the stepping down of an opened source when things gets out of control.
/// Used when session state and source state become out of sync.
/// This should be called on the Thread that originally called the <see cref="EnableSource"/>
/// method, if applicable.
/// </summary>
/// <param name="targetState">State of the target.</param>
public void ForceStepDown(int targetState)