public async Task RaiseAsync(InteractionMessage message) { if (message == null) { throw new ArgumentNullException(nameof(message)); } if (!message.IsFrozen) { message.Freeze(); } await Task.Factory.StartNew(() => Raise(message)); }
public void Raise(InteractionMessage message) { if (message == null) { throw new ArgumentNullException(nameof(message)); } var threadSafeHandler = Interlocked.CompareExchange(ref Raised, null, null); if (threadSafeHandler != null) { if (!message.IsFrozen) { message.Freeze(); } threadSafeHandler(this, new InteractionMessageRaisedEventArgs(message)); } }
public void RaiseAsync(InteractionMessage message) { if (message == null) { throw new ArgumentException("messageはnullにできません"); } if (!message.IsFrozen) { message.Freeze(); } var task = Task.Factory.StartNew(() => Raise(message), CancellationToken.None, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); task.ContinueWith(t => { var e = new AsyncMessageFailedEventArgs(t.Exception); OnAsyncMessageFailed(e); t.Exception.Handle(ex => true); }, TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously); }