예제 #1
0
        public async Task InvokeAsync(string Method, long worksize, params object[] Args)
        {
            ComputeKernel    kernel    = CreateKernel(Method, Args);
            ComputeEventList eventList = new ComputeEventList();

            InvokeStarted?.Invoke(this, EventArgs.Empty);
            string jid = Guid.NewGuid().ToString();
            AsyncManualResetEvent evt = new AsyncManualResetEvent(false);

            lock (CompletionLocks)
            {
                CompletionLocks.Add(jid, evt);
            }

            queue.Execute(kernel, null, new long[] { worksize }, null, eventList);

            eventList[0].Completed += (sender, e) => EasyCL_Completed(sender, jid);
            eventList[0].Aborted   += (sender, e) => EasyCL_Aborted(sender, Method);

            await evt.WaitAsync();

            lock (CompletionLocks)
            {
                CompletionLocks.Remove(jid);
            }
        }
예제 #2
0
 public void Raise(object sender, TEventArgs e)
 {
     InvokeStarted?.Invoke(this, null);
     lock (_handlers)
     {
         _handlers.RemoveAll(h => !h.Invoke(sender, e));
     }
     InvokeEnded?.Invoke(this, null);
 }
예제 #3
0
        public void Invoke(string Method, long Offset, long Worksize, params object[] Args)
        {
            ComputeKernel kernel = CreateKernel(Method, Args);

            ComputeEventList eventList = new ComputeEventList();

            InvokeStarted?.Invoke(this, EventArgs.Empty);

            queue.Execute(kernel, new long[] { Offset }, new long[] { Worksize }, null, eventList);

            eventList[0].Completed += (sender, e) => EasyCL_Completed(sender, null);
            eventList[0].Aborted   += (sender, e) => EasyCL_Aborted(sender, Method);

            queue.Finish();
        }
예제 #4
0
        /// <summary>
        /// Subsequent calls to Invoke work faster without arguments
        /// </summary>
        public void Invoke(string Method, long Offset, long Worksize)
        {
            if (LastKernel == null)
            {
                throw new InvalidOperationException("You need to call Invoke with arguments before. All Arguments are saved");
            }

            ComputeEventList eventList = new ComputeEventList();

            InvokeStarted?.Invoke(this, EventArgs.Empty);

            queue.Execute(LastKernel, new long[] { Offset }, new long[] { Worksize }, null, eventList);

            eventList[0].Completed += (sender, e) => EasyCL_Completed(sender, null);
            eventList[0].Aborted   += (sender, e) => EasyCL_Aborted(sender, Method);

            queue.Finish();
        }
예제 #5
0
        public void RaiseAsync(object sender, TEventArgs e, Predicate <object> filter)
        {
            InvokeStarted?.Invoke(sender, e as System.EventArgs);
            var asyncRaise = new Task <List <WeakDelegate> >(() =>
            {
                var result      = new List <WeakDelegate>();
                var handlerCopy = new List <WeakDelegate>(_handlers); // Local copy to play around with.
                foreach (var handler in handlerCopy)
                {
                    if (filter != null)
                    {
                        if (!filter(handler.GetTargetInstance()))
                        {
                            continue;
                        }
                    }
                    try
                    {
                        if (!handler.Invoke(sender, e))
                        {
                            result.Add(handler);
                        }
                    }
                    catch (Exception ex)
                    {
                        AsyncRaiseFailed?.Invoke(sender, new EventFailedEventArgs(e as System.EventArgs, ex));
                    }
                }
                return(result);
            });

            asyncRaise.ContinueWith((delegate(Task <List <WeakDelegate> > task)
            {
                lock (_handlers)
                {
                    _handlers.RemoveAll(x => task.Result.Contains(x));
                }
                InvokeEnded?.Invoke(sender, e as System.EventArgs);
            }));

            asyncRaise.Start();
        }