mirror of
https://github.com/soukoku/ntwain.git
synced 2026-02-25 13:04:07 +08:00
Added musings on runnig as Console app.
This commit is contained in:
50
NTwain/AsyncPump.cs
Normal file
50
NTwain/AsyncPump.cs
Normal 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);
|
||||
// }
|
||||
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -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" />
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user