public override void Send(SendOrPostCallback d, object state) { lock (_mutex) { d(state); } }
internal SendOrPostCallbackItem(SendOrPostCallback callback, object state, ExecutionType type) { mMethod = callback; mState = state; mExeType = type; }
public override void Post(SendOrPostCallback d, object state) { // queue the item and don't wait for its execution. This is risky because // an unhandled exception will terminate the STA thread. Use with caution. SendOrPostCallbackItem item = new SendOrPostCallbackItem(d, state, ExecutionType.Post); mQueue.Enqueue(item); }
private void VerifyDelegateNotNull(SendOrPostCallback d) { if (d == null) { throw new ArgumentNullException(SR.GetString("Async_NullDelegate"), "d"); } }
/// <summary> /// Initializes a new instance of the <see cref="SynchronizationContextAwaiter"/> struct. /// </summary> /// <param name="context">The context.</param> public SynchronizationContextAwaiter([NotNull] SynchronizationContext context) { if (context == null) throw new ArgumentNullException("context"); _context = context; // ReSharper disable once PossibleNullReferenceException _executor = a => ((Action)a)(); }
public override void Send(SendOrPostCallback d, object state) { SynchronizationContext oldContext = SynchronizationContext.Current; SynchronizationContext.SetSynchronizationContext(this); d.Invoke(state); SynchronizationContext.SetSynchronizationContext(oldContext); }
public override void Post(SendOrPostCallback d, object state) { lock (_postedCallbacks) { _postedCallbacks.Add(Tuple.Create(d, state)); } }
public override void Send (SendOrPostCallback d, object state) { if (state is Exception) { ++SendCounter; base.Send (d, state); } }
public void Post(SendOrPostCallback callback, object state) { #region Contracts if (callback == null) throw new ArgumentNullException(); #endregion // Create Action action = delegate() { try { callback(state); } catch (Exception ex) { Debug.Fail(string.Format("Delegate:{0}, State:{1}, Message:{2}", callback.GetType(), "Exception", ex.Message)); } }; // Set lock (_syncRoot) { // Require if (_operateState != OperateState.Started) throw new InvalidOperationException(); if (_executeThreadState != OperateState.Started) throw new InvalidOperationException(); // Attach _executeActionQueue.Enqueue(action); } }
public override void Send(SendOrPostCallback d, object state) { #if !dotNETCF10 contextControl.Invoke(d, new object[] { state }); #else contextControl.Invoke(new EventHandler(new EventHandleCreate(d, state).EventHandler)); #endif }
private AsyncSendData(AsyncDataHandler handler, Uri uriToUse, AtomEntry entry, AtomFeed feed, SendOrPostCallback callback, object userData, bool parseFeed) : base(uriToUse, null, userData, callback, parseFeed) { this.DataHandler = handler; this.entry = entry; this.Feed = feed; }
/// <inheritdoc/> public override void Send(SendOrPostCallback d, object state) { if (Dispatcher.UIThread.CheckAccess()) d(state); else Dispatcher.UIThread.InvokeTaskAsync(() => d(state)).Wait(); }
public virtual void Post(SendOrPostCallback d, object state) { #if (dotNET10 || dotNET11 || dotNETCF10) ThreadPool.QueueUserWorkItem(new WaitCallback(d), state); #else ThreadPool.QueueUserWorkItem(d.Invoke, state); #endif }
/// <summary> /// Initializes a new instance of the <see cref="ImageListViewCacheThumbnail"/> class. /// </summary> /// <param name="owner">The owner control.</param> public ImageListViewCacheThumbnail(ImageListView owner) { context = null; bw = new QueuedBackgroundWorker(); bw.ProcessingMode = ProcessingMode.LIFO; bw.IsBackground = true; bw.DoWork += bw_DoWork; bw.RunWorkerCompleted += bw_RunWorkerCompleted; checkProcessingCallback = new SendOrPostCallback(CanContinueProcessing); mImageListView = owner; CacheMode = CacheMode.OnDemand; CacheLimitAsItemCount = 0; CacheLimitAsMemory = 20 * 1024 * 1024; RetryOnError = false; thumbCache = new Dictionary<Guid, CacheItem>(); editCache = new Dictionary<Guid, bool>(); processing = new Dictionary<Guid, bool>(); processingRendererItem = Guid.Empty; processingGalleryItem = Guid.Empty; rendererItem = null; galleryItem = null; MemoryUsed = 0; MemoryUsedByRemoved = 0; removedItems = new List<Guid>(); disposed = false; }
public Functions() { #region Initialize Delegates for Database Commands onGetProfileCompletedDelegate = new SendOrPostCallback(GetProfileCompleted); onGetServersCompletedDelegate = new SendOrPostCallback(GetServersCompleted); #endregion }
public Event(SendOrPostCallback callback, object state, bool isSend) { this.callback = callback; this.state = state; resetEvent = new ManualResetEvent(!isSend); }
public static void Post(SendOrPostCallback callback, object state = null) { lock (s_posts) { s_posts.Add(Tuple.Create(callback, state)); } }
/// <summary> /// Dispatch a single job to the target thread and return immediately. /// This method can be called in background thread. /// </summary> /// <param name="callback">The callback which you wants to dispatch</param> public override void Post(SendOrPostCallback callback, object state) { jobs.Add(() => { callback.Invoke(state); }); }
public SendOrPostCallbackItem(SendOrPostCallback callback, object state, ExecutionType type) { _method = callback; _state = state; _exeType = type; }
public override void Send(SendOrPostCallback d, object state) { if (System.Threading.Thread.CurrentThread.ManagedThreadId == ApplicationHandler.MainThreadID) { d(state); } else { var evt = new ManualResetEvent(false); Exception exception = null; Idle.Add(() => { try { d(state); } catch (Exception ex) { exception = ex; } finally { evt.Set(); } return false; }); evt.WaitOne(); if (exception != null) throw exception; } }
/// <summary> /// <see cref="SynchronizationContext.Post(SendOrPostCallback, object)"/> /// </summary> /// <param name="d"></param> /// <param name="state"></param> public override void Post(SendOrPostCallback d, object state) { lock (_sync) { _actions.Add(() => d(state)); } }
public override void Post(SendOrPostCallback d, object state) { lock (list) { list.Add(() => d(state)); } }
public CallbackItem(SendOrPostCallback item, object state) { this.Id = Guid.NewGuid(); this.executionCompleted = new ManualResetEvent(false); this.callback = item; this.state = state; }
public override async void Post(SendOrPostCallback d, object state) { // The call to Post() may be the state machine signaling that an exception is // about to be thrown, so we make sure the operation count gets incremented // before the Task.Run, and then decrement the count when the operation is done. OperationStarted(); try { // await and eat exceptions that come from this post // We could get a thread abort, so we need to handle that await Task.Run(() => { try { Send(d, state); } finally { OperationCompleted(); } }).ConfigureAwait(false); } catch { } }
void Invoke(SendOrPostCallback d, object state, bool sync) { if (sync) sc.Send(d,state); else sc.Post(d, state); }
public void Post(string resource, Dictionary<string, string> parameters, SendOrPostCallback onComplete) { var uriPath = resource; var uri = new Uri(uriPath, UriKind.Absolute); var httpWebRequest = (HttpWebRequest)WebRequest.Create(uri); httpWebRequest.Method = "POST"; var writeRequest = new AsyncCallback(e => { httpWebRequest.ContentType = "application/x-www-form-urlencoded"; var stream = httpWebRequest.EndGetRequestStream(e); var postData = string.Empty; foreach (var key in parameters.Keys) { postData += key + "=" + parameters[key] + "&"; } var streamWriter = new StreamWriter(stream); streamWriter.Write(postData); streamWriter.Close(); stream.Close(); httpWebRequest.BeginGetResponse(x => synchronizationContext.Post(onComplete, x), null); }); httpWebRequest.BeginGetRequestStream(writeRequest, null); }
/// <summary> /// Initializes a new instance of the <see cref="SynchronizedCall"/> class. /// </summary> /// <param name="callback">The call to marshal.</param> /// <param name="state">The state to provide to the call. <see langword="null"/> is fine if you don't need to include any state.</param> public SynchronizedCall(SendOrPostCallback callback, object state) { Throw.If.Null(callback, "callback"); this.callback = callback; this.state = state; }
/// <summary> /// Post a call to the specified method on the creator thread /// </summary> /// <param name="callback">Method that is to be called</param> /// <param name="state">Method parameter/state</param> public void AsyncPost(SendOrPostCallback callback, object state) { if (IsAsyncCreatorThread) callback(state); // Call the method directly else AsynchronizationContext.Post(callback, state); // Post on creator thread }
public override void Post(SendOrPostCallback d, object state) { if (mQueue.IsAddingCompleted) throw new SynchronizationContextCompletedException(); mQueue.Add(new KeyValuePair<SendOrPostCallback, object>(d, state)); }
public override void Post(SendOrPostCallback d, object state) { if (isSingleThread) Queue.Add(new KeyValuePair<SendOrPostCallback, object>(d, state)); else base.Post(chainedState => CallWithOperationContext(d, state), state); }
public override void Post(SendOrPostCallback method, object state) { WorkItem workItem = new WorkItem(method, state); QueueWorkItem(workItem); }
public override void Send(SendOrPostCallback d, object state) { _vs.Invoke <object>(() => { d(state); return(null); }); }
public override void Post(SendOrPostCallback d, object state) { _vs.Invoke(() => d(state)); }
public override void Post(SendOrPostCallback d, object state) { OperationContext.Current = context; d(state); }
public override void Send(SendOrPostCallback d, object state) { _syncContext.Send(d, state); }
public override void Post(SendOrPostCallback d, object state) { _syncContext.Post(WrapCallback(d), state); }
/// <summary> /// Dispatches an asynchronous message to the synchronization context. /// </summary> /// <param name = "d">The System.Threading.SendOrPostCallback delegate to call.</param> /// <param name = "state">The object passed to the delegate.</param> public override void Post(SendOrPostCallback d, object state) { Task.Factory.StartNew(() => d(state), CancellationToken.None, TaskCreationOptions.None, m_scheduler); }
/// <summary> /// Initializes a nex instance of the <see cref="Progress{TValue}"/> class. /// </summary> public Progress() { this.mSynchronizationContext = SynchronizationContext.Current; this.mInvokeHandlers = new SendOrPostCallback(this.InvokeHandlers); }
public override void Send(SendOrPostCallback d, object state) { Interlocked.Increment(ref sendCount); base.Send(d, state); }
void Initialize() { if (port == defaultPort || port == 0) { new SmtpPermission(SmtpAccess.Connect).Demand(); } else { new SmtpPermission(SmtpAccess.ConnectToUnrestrictedPort).Demand(); } transport = new SmtpTransport(this); if (Logging.On) { Logging.Associate(Logging.Web, this, transport); } onSendCompletedDelegate = new SendOrPostCallback(SendCompletedWaitCallback); if (MailConfiguration.Smtp != null) { if (MailConfiguration.Smtp.Network != null) { if (host == null || host.Length == 0) { host = MailConfiguration.Smtp.Network.Host; } if (port == 0) { port = MailConfiguration.Smtp.Network.Port; } transport.Credentials = MailConfiguration.Smtp.Network.Credential; transport.EnableSsl = MailConfiguration.Smtp.Network.EnableSsl; if (MailConfiguration.Smtp.Network.TargetName != null) { targetName = MailConfiguration.Smtp.Network.TargetName; } // If the config file contains a domain to be used for the // domain element in the client's EHLO or HELO message, // use it. // // We do not validate whether the domain specified is valid. // It is up to the administrators or user to use the right // value for their scenario. // // Note: per section 4.1.4 of RFC2821, the domain element of // the HELO/EHLO should be used for logging purposes. An // SMTP server should not decide to route an email based on // this value. clientDomain = MailConfiguration.Smtp.Network.ClientDomain; } deliveryFormat = MailConfiguration.Smtp.DeliveryFormat; deliveryMethod = MailConfiguration.Smtp.DeliveryMethod; if (MailConfiguration.Smtp.SpecifiedPickupDirectory != null) { pickupDirectoryLocation = MailConfiguration.Smtp.SpecifiedPickupDirectory.PickupDirectoryLocation; } } if (host != null && host.Length != 0) { host = host.Trim(); } if (port == 0) { port = defaultPort; } if (this.targetName == null) { targetName = "SMTPSVC/" + host; } if (clientDomain == null) { // We use the local host name as the default client domain // for the client's EHLO or HELO message. This limits the // information about the host that we share. Additionally, the // FQDN is not available to us or useful to the server (internal // machine connecting to public server). // SMTP RFC's require ASCII only host names in the HELO/EHLO message. string clientDomainRaw = IPGlobalProperties.InternalGetIPGlobalProperties().HostName; IdnMapping mapping = new IdnMapping(); try { clientDomainRaw = mapping.GetAscii(clientDomainRaw); } catch (ArgumentException) { } // For some inputs GetAscii may fail (bad Unicode, etc). If that happens // we must strip out any non-ASCII characters. // If we end up with no characters left, we use the string "LocalHost". This // matches Outlook behavior. StringBuilder sb = new StringBuilder(); char ch; for (int i = 0; i < clientDomainRaw.Length; i++) { ch = clientDomainRaw[i]; if ((ushort)ch <= 0x7F) { sb.Append(ch); } } if (sb.Length > 0) { clientDomain = sb.ToString(); } else { clientDomain = "LocalHost"; } } }
public override void Send(SendOrPostCallback d, object state) { throw new NotSupportedException("Synchronously sending is not supported."); }
/// <summary> /// Invokes the callback in the synchronization context asynchronously. The callback is placed in the action queue. /// </summary> /// <param name="d">The delegate to call.</param> /// <param name="state">The object passed to the delegate.</param> /// <threadsafety>This method may be called by any thread at any time.</threadsafety> public override void Post(SendOrPostCallback d, object state) { this.actionDispatcher.QueueAction(() => d(state)); }
public virtual void Send(SendOrPostCallback d, object state) { d(state); }
public override void Post(SendOrPostCallback d, object state) { Interlocked.Increment(ref postCount); base.Post(d, state); }
public override void Send(SendOrPostCallback d, object state) { throw new NotSupportedException("We cannot send to our same thread"); }
public override void Send(SendOrPostCallback d, object state) { throw new NotSupportedException(SR.InvalidOperation_SendNotSupportedOnWindowsRTSynchronizationContext); }
public override void Post(SendOrPostCallback d, object state) { SynchronizationManager.RunMacroSynchronization.RunAsMacroAsync(d, state); }
public virtual void Post(SendOrPostCallback d, object state) { ThreadPool.QueueUserWorkItem(new WaitCallback(d), state); }
public WorkItem(SendOrPostCallback callback, object state) { _callback = callback; _state = state; }
public override void Send(SendOrPostCallback d, object state) { throw new NotImplementedException("ExcelSynchronizationContext does not currently allow synchronous calls."); }
public virtual void Send(SendOrPostCallback d, object?state) => d(state);
/// <summary>Dispatches an asynchronous message to a synchronization context.</summary> public override void Post(SendOrPostCallback d, object state) { var task = new Task(() => d(state)); task.Start(m_poller); }
public override void Post(SendOrPostCallback d, object state) { scheduler.Schedule(state, (self, s) => { d(s); return(Disposable.Empty); }); }
public virtual void Post(SendOrPostCallback d, object?state) => ThreadPool.QueueUserWorkItem(static s => s.d(s.state), (d, state), preferLocal: false);
public virtual void QueueAsMacro(SendOrPostCallback callback, object state) { throw new NotImplementedException(); }
/// <summary> // StaticFunctions.InvokeIfRequiredAsync(StaticFunctions.BaseContext, // para => // { // }, null); /// </summary> /// <param name="context"></param> /// <param name="callback"></param> /// <param name="state"></param> public static void InvokeIfRequiredAsync(SynchronizationContext context, SendOrPostCallback callback, object state) { context.Post(callback, state); //모든 프레임웍에서 동작할려면 이거 써야한다는데.. }
public override void Post(SendOrPostCallback function, object state) { _continuations.Enqueue(Tuple.Create(function, state)); }
public static SendOrPostCallback ThunkCallback(SendOrPostCallback callback) { return((new SendOrPostThunk(callback)).ThunkFrame); }
public override void Post(SendOrPostCallback d, object state) { actions.Enqueue(new Entry(d, state)); }
public override void Post(SendOrPostCallback d, object state) { _items.Enqueue(Tuple.Create(d, state)); _workItemsWaiting.Set(); }