Пример #1
0
 public TaskHandlerStatus(Action <int> onCompleted, ComHandlerUpdate onUpdate)
 {
     OnCompleted = onCompleted;
     OnUpdate    = onUpdate;
 }
Пример #2
0
 /// <summary>
 /// Runs an action that is defined via a COM handler. COM CLSID must be registered to an object that implements the <see cref="ITaskHandler" /> interface.
 /// </summary>
 /// <param name="clsid">The CLSID of the COM object.</param>
 /// <param name="onComplete">The action to run on thread completion.</param>
 /// <param name="data">An optional string passed to the COM object at startup.</param>
 /// <param name="millisecondsTimeout">The number of milliseconds to wait or -1 for indefinitely.</param>
 /// <param name="onUpdate">An optional <see cref="ComHandlerUpdate" /> delegate that is called when the COM object calls the <see cref="ITaskHandlerStatus.UpdateStatus(short, string)" /> method.</param>
 public static void RunComHandlerActionAsync(Guid clsid, Action <int> onComplete, string data = null, int millisecondsTimeout = -1, ComHandlerUpdate onUpdate = null)
 {
     new ComHandlerThread(clsid, data, millisecondsTimeout, onUpdate, onComplete).Start();
 }
Пример #3
0
 public ComHandlerThread(Guid clsid, string data, int millisecondsTimeout, ComHandlerUpdate onUpdate, Action <int> onComplete)
 {
     objType = Type.GetTypeFromCLSID(clsid, true);
     Data    = data;
     Timeout = millisecondsTimeout;
     status  = new TaskHandlerStatus(i =>
     {
         completed.Set();
         onComplete?.Invoke(i);
     }, onUpdate);
 }
Пример #4
0
        /// <summary>
        /// Runs an action that is defined via a COM handler. COM CLSID must be registered to an object that implements the <see cref="ITaskHandler" /> interface.
        /// </summary>
        /// <param name="clsid">The CLSID of the COM object.</param>
        /// <param name="data">An optional string passed to the COM object at startup.</param>
        /// <param name="millisecondsTimeout">The number of milliseconds to wait or -1 for indefinitely.</param>
        /// <param name="onUpdate">An optional <see cref="ComHandlerUpdate" /> delegate that is called when the COM object calls the <see cref="ITaskHandlerStatus.UpdateStatus(short, string)" /> method.</param>
        /// <returns>
        /// The value set by the COM object via a call to the <see cref="ITaskHandlerStatus.TaskCompleted(int)" /> method.
        /// </returns>
        public static int RunComHandlerAction(Guid clsid, string data = null, int millisecondsTimeout = -1, ComHandlerUpdate onUpdate = null)
        {
            var thread = new ComHandlerThread(clsid, data, millisecondsTimeout, onUpdate, null);

            thread.Start().Join();
            return(thread.ReturnCode);
        }