private FMOD.RESULT endPlayCallbackFunction(IntPtr channelRaw, FMOD.CHANNEL_CALLBACKTYPE tipo, int comando, uint datoComando1, uint datoComando2) { lock (sequentialPlayList) { if (sequentialPlayList.Count == 0) { return(FMOD.RESULT.ERR_INVALID_PARAM); } sequentialPlayList.RemoveAt(0); try { if (sequentialPlayList.Count != 0) { if (invoker.InvokeRequired) { invoker.Invoke(new PlaySoundEventHandler(PlaySoundCallback), new object[] { houses[this.houseId][(short)this.sequentialPlayList[0]] }); } else { PlaySoundCallback(houses[this.houseId][(short)this.sequentialPlayList[0]]); } } } catch { return(FMOD.RESULT.ERR_INITIALIZATION); } return(FMOD.RESULT.OK); } }
protected void Raise(EventArgs e) { #region Comments //Para o modelo de eventos do COM, quando o tipo é exatamente EventArgs, não necessita enviá-lo. #endregion Comments if (eventHandler != null) { ISynchronizeInvoke synchronizeInvoke = eventHandler.Target as ISynchronizeInvoke; if (e.GetType() == typeof(EventArgs)) { if (synchronizeInvoke == null) { eventHandler.DynamicInvoke(); } else { synchronizeInvoke.Invoke(eventHandler, null); } } else { if (synchronizeInvoke == null) { eventHandler.DynamicInvoke(e); } else { synchronizeInvoke.Invoke(eventHandler, new object[] { e }); } } } }
/// <summary> /// Add input /// </summary> /// <param name="input">Input</param> public void AddInput(IFuzzingInput input) { if (Inputs == null) { return; } if (_Invoker != null && _Invoker.InvokeRequired) { _Invoker.Invoke(new delAddInput(AddInput), new object[] { input }); return; } lock (Inputs) Inputs.Add(new FuzzerStat <IFuzzingInput>(input)); }
/// <summary> /// Метод генерирует событие DataWasChanged /// </summary> protected void OnDataWasChanged() { EventArgs args = new EventArgs(); EventHandler handler = this.DataWasChanged; if (handler != null) { foreach (EventHandler SingleCast in handler.GetInvocationList()) { ISynchronizeInvoke syncInvoke = SingleCast.Target as ISynchronizeInvoke; try { if ((syncInvoke != null) && (syncInvoke.InvokeRequired)) { syncInvoke.Invoke(SingleCast, new Object[] { this, args }); } else { SingleCast(this, args); } } catch { throw; } } } return; }
/// <summary> /// Raises the <see cref="E:EncodingFinished"/> event. /// </summary> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> /// <remarks>Documented by Dev02, 2008-04-14</remarks> public void OnEncodingFinished(EventArgs e) { EventHandler Handler = EncodingFinished; if (Handler != null) { foreach (EventHandler Caster in Handler.GetInvocationList()) { ISynchronizeInvoke SyncInvoke = Caster.Target as ISynchronizeInvoke; try { if (SyncInvoke != null && SyncInvoke.InvokeRequired) { SyncInvoke.Invoke(Handler, new object[] { this, e }); } else { Caster(this, e); } } catch { } } } }
/// <summary> /// Метод генерирует событие изменения состояния сетевого сервиса /// </summary> protected void OnStatusChanged() { EventArgs args = new EventArgs(); EventHandler handler = this.ServiceChangedStatus; if (handler != null) { foreach (EventHandler SingleCast in handler.GetInvocationList()) { ISynchronizeInvoke syncInvoke = SingleCast.Target as ISynchronizeInvoke; try { if ((syncInvoke != null) && (syncInvoke.InvokeRequired)) { syncInvoke.Invoke(SingleCast, new Object[] { this, args }); } else { SingleCast(this, args); } } catch { throw; } } } //String traceMessage = String.Format( // "Сеть {0}: Сервис {1}: Принял новое состояние {2}", // this._NetworkController.NetworkName, // this.ServiceName.ToString(), this._Status.ToString()); return; }
public static void InvokeMulticast(object sender, MulticastDelegate md, EventArgs e) { if (md == null) { return; } foreach (StdMulticastDelegation Caster in md.GetInvocationList()) { ISynchronizeInvoke SyncInvoke = Caster.Target as ISynchronizeInvoke; try { if (SyncInvoke != null && SyncInvoke.InvokeRequired) { SyncInvoke.Invoke(Caster, new object[] { sender, e }); } else { Caster(sender, e); } } catch (System.Exception ex) { Console.WriteLine("Event handling failed. \n"); Console.WriteLine("{0}:\n", ex.ToString()); } } }
/////////////////////////////////////////////////////////////////////// private static bool Invoke( ISynchronizeInvoke synchronizeInvoke, Delegate method, bool strict, ref object result, params object[] args ) { if (synchronizeInvoke != null) { if (strict && IsDisposed(synchronizeInvoke)) { return(false); } if (synchronizeInvoke.InvokeRequired) { result = synchronizeInvoke.Invoke(method, args); } else { result = method.DynamicInvoke(args); } return(true); } return(false); }
/// <summary> /// 当有信息进入时候 /// </summary> private void DoAccept(object objClient) { Socket client = objClient as Socket; if (client == null) { return; } NetConnection conn = new NetConnection(client); byte[] tmpByte = conn.Receive(); if (OnClientReceive != null) { if (_synInvoker != null) { _synInvoker.Invoke(OnClientReceive, new object[] { conn, tmpByte }); } else { OnClientReceive(conn, tmpByte); } } conn.CloseConnection(); }
public static void InvokeMulticast(object sender, MulticastDelegate md, EventArgs e) { if ((object)md == null) { return; } foreach (SysPost.StdMulticastDelegation invocation in md.GetInvocationList()) { ISynchronizeInvoke target = invocation.Target as ISynchronizeInvoke; try { if (target != null && target.InvokeRequired) { target.Invoke((Delegate)invocation, new object[2] { sender, (object)e }); } else { invocation(sender, e); } } catch (Exception ex) { Console.WriteLine("Event handling failed. \n"); Console.WriteLine("{0}:\n", (object)ex.ToString()); } } }
private void AsyncProcessParent(object args) { this._syncEventExiting.Reset(); this._syncEventExited.Reset(); if (Tools.AnyToInt(args) > 0) { Thread.Sleep(Tools.AnyToInt(args)); } this._exitCode = this.AsyncProcedure(); this._syncEventExited.Set(); if (this.AsyncProcStopped != null) { ISynchronizeInvoke synchronizeInvoke = this.AsyncProcStopped.Target as ISynchronizeInvoke; if (synchronizeInvoke != null) { synchronizeInvoke.Invoke(this.AsyncProcStopped, new object[] { this, new EventArgs() }); return; } this.AsyncProcStopped(this, new EventArgs()); } }
protected virtual void OnHandler(UFEPacket resp, ReceivedHandler handler) { //if (resp.Id > 0) //{ // UFEFuture.OnCompleted(resp); // return; //} if (handler != null) { ISynchronizeInvoke hwnd = handler.Target as ISynchronizeInvoke; if (hwnd != null) { if (hwnd.InvokeRequired) { hwnd.Invoke(handler, new object[] { resp }); } else { handler.DynamicInvoke(resp); } } else { var old = CheckForIllegalCrossThreadCalls; CheckForIllegalCrossThreadCalls = false; handler.DynamicInvoke(resp); CheckForIllegalCrossThreadCalls = old; } } }
private static void InternalInvokeMethod(ISynchronizeInvoke hwnd, Delegate method, params object[] args) { Check.Assert(hwnd != null); Check.Assert(method != null); if (hwnd.InvokeRequired) { hwnd.Invoke(method, args); } else { try { method.DynamicInvoke(args); } catch { try { System.Threading.SynchronizationContext.Current.Post((state) => method.DynamicInvoke(args), null); } finally { } } } }
/* This function sends events to whoever is listening. * This uses some logic to not step on the toes of other threads. Primarily for the sake of mainview. * https://www.codeproject.com/Articles/11848/Another-Way-to-Invoke-UI-from-a-Worker-Thread */ protected virtual void OnWifiLedUpdate() { //WifiLedUpdated?.Invoke(this, EventArgs.Empty); EventHandler <EventArgs> handler = WifiLedUpdated; if (null != handler) {//not quite sure why there are so many null checks, I guess sanity checks? foreach (EventHandler <EventArgs> singleCast in handler.GetInvocationList()) { ISynchronizeInvoke syncInvoke = singleCast.Target as ISynchronizeInvoke; try { if ((null != syncInvoke) && (syncInvoke.InvokeRequired)) { syncInvoke.Invoke(singleCast, new object[] { this, EventArgs.Empty }); } else { singleCast(this, EventArgs.Empty); } } catch (Exception e) { Debug.WriteLine("[OnWifiLedUpdate] Encountered an exception: " + e.Message); } } } }
private void OnGameOver() { EventHandler temp = GameOver; if (temp != null) { if (synchronizingObject != null) { synchronizingObject.Invoke(temp, new object[] { EventArgs.Empty }); } else { temp(this, EventArgs.Empty); } } }
void InvokeDelegate(Delegate del, params object[] args) { ISynchronizeInvoke synchronizer = del.Target as ISynchronizeInvoke; Debug.Assert(synchronizer != null); if (synchronizer.InvokeRequired == false) { try { del.DynamicInvoke(args); } catch (Exception e) { Trace.WriteLine(e.Message); } return; } try { synchronizer.Invoke(del, args); } catch (Exception e) { Trace.WriteLine(e.Message); } }
/// <summary> /// The 'On Copy Error' Event Handler: Called when an Attempted Copy of a file Fails. /// </summary> /// <param name="e">The 'Copy Error' Event Arguments.</param> protected virtual void OnCopyError(CopyErrorEventArgs e) { CopyErrorEventHandler Handler = CopyError; if (Handler != null) { foreach (CopyErrorEventHandler Caster in Handler.GetInvocationList()) { ISynchronizeInvoke syncInvoke = Caster.Target as ISynchronizeInvoke; try { if (syncInvoke != null && syncInvoke.InvokeRequired) { syncInvoke.Invoke(Handler, new object[] { this, e }); } else { Caster(this, e); } } catch { } } } }
/// <summary> /// The 'On Item Indexed' Event Handler: Called when an Item (File or Folder) Is Indexed /// </summary> /// <param name="e">The 'Item Indexed' Event Arguments.</param> protected virtual void OnItemIndexed(ItemIndexedEventArgs e) { ItemIndexedEventHandler Handler = ItemIndexed; if (Handler != null) { foreach (ItemIndexedEventHandler Caster in Handler.GetInvocationList()) { ISynchronizeInvoke SyncInvoke = Caster.Target as ISynchronizeInvoke; try { if (SyncInvoke != null && SyncInvoke.InvokeRequired) { SyncInvoke.Invoke(Handler, new object[] { this, e }); } else { Caster(this, e); } } catch { } } } }
/// <summary> /// Метод для генерации события приёма сообщения /// </summary> private void OnMessageReceived() { EventHandler handler = this.MessageReceived; if (handler != null) { foreach (EventHandler SingleCast in handler.GetInvocationList()) { ISynchronizeInvoke syncInvoke = SingleCast.Target as ISynchronizeInvoke; try { if ((syncInvoke != null) && (syncInvoke.InvokeRequired)) { syncInvoke.Invoke(SingleCast, new Object[] { this, new EventArgs() }); } else { SingleCast(this, new EventArgs()); } } catch { throw; } } } }
/// <summary> /// Генерирует событие при возникновении ошибок в CAN адаптере /// </summary> private void OnErrorReceived(ERROR error) { EventHandlerErrorRecived handler = this.ErrorReceived; EventArgsLineErrorRecived args = new EventArgsLineErrorRecived(error); if (handler != null) { foreach (EventHandler SingleCast in handler.GetInvocationList()) { ISynchronizeInvoke syncInvoke = SingleCast.Target as ISynchronizeInvoke; try { if ((syncInvoke != null) && (syncInvoke.InvokeRequired)) { syncInvoke.Invoke(SingleCast, new Object[] { this, args }); } else { SingleCast(this, args); } } catch { throw; } } } }
/// <summary> /// Raises the <see cref="E:ProgressChanged"/> event. /// </summary> /// <param name="e">The <see cref="MLifterAudioBookGenerator.ProgressChangedEventArgs"/> instance containing the event data.</param> /// <remarks>Documented by Dev02, 2008-05-20</remarks> public static void OnProgressChanged(ProgressChangedEventArgs e) { ProgressChangedEventHandler handler = ProgressChanged; if (handler != null) { foreach (ProgressChangedEventHandler caster in handler.GetInvocationList()) { ISynchronizeInvoke SyncInvoke = caster.Target as ISynchronizeInvoke; try { if (SyncInvoke != null && SyncInvoke.InvokeRequired) { SyncInvoke.Invoke(handler, new object[] { null, e }); } else { caster(null, e); } } catch { } } } }
public static void Printf(LogWndOpt opt, string format, params object[] args) { string formatted = string.Format(format, args); foreach (LoggingHandler Caster in Receivers.GetInvocationList()) { ISynchronizeInvoke SyncInvoke = Caster.Target as ISynchronizeInvoke; try { if (SyncInvoke != null && SyncInvoke.InvokeRequired) { SyncInvoke.Invoke(Caster, new object[] { opt, formatted }); } else { Caster(opt, formatted); } } catch (System.Exception ex) { Console.WriteLine("UsLogging.Printf() failed. \n"); Console.WriteLine("{0}:\n", ex.ToString()); } } }
private void EhThreadBody() { while (_keepThreadRunning) { try { ProcessInvokerQueue(); _triggeringEvent.WaitOne(_safetyIntervalTime_msec); } catch (Exception ex) { // the exception must be re-thrown on the Gui thread in order to be handled _dispatcherForReThrowingExceptions.Invoke((Action <Exception>)ReThrow, new object[] { ex }); } } // Process the invoker queue one last time ProcessInvokerQueue(); var locTriggerEvent = _triggeringEvent; if (null != locTriggerEvent) { locTriggerEvent.Dispose(); } _triggeringEvent = null; _thread = null; }
public void OnConflict(object sender, SvnConflictEventArgs e) { if (_synchronizer != null && _synchronizer.InvokeRequired) { // If needed marshall the call to the UI thread e.Detach(); // Make this instance thread safe! _synchronizer.Invoke(new EventHandler <SvnConflictEventArgs>(OnConflict), new object[] { sender, e }); return; } AnkhConfig config = GetService <IAnkhConfigurationService>().Instance; if (config.InteractiveMergeOnConflict) { // Only call interactive merge if the user opted in on it if (_currentMergeConflictHandler == null) { _currentMergeConflictHandler = CreateMergeConflictHandler(); } _currentMergeConflictHandler.OnConflict(e); } }
private static void InvokeIfRequired(ISynchronizeInvoke control, MethodInvoker action) { if (control.InvokeRequired) control.Invoke(action, new object[0]); else action(); }
/// ------------------------------------------------------------------------------------ private WaveStreamProvider GetWaveStreamForOralAnnotationSegment(string filename, AudioRecordingType annotationType) { var provider = WaveStreamProvider.Create(_output1ChannelAudioFormat, filename); if (provider.Error != null && !(provider.Error is FileNotFoundException)) { var msg = LocalizationManager.GetString( "SessionsView.Transcription.GeneratedOralAnnotationView.ProcessingAnnotationFileErrorMsg", "There was an error processing a {0} annotation file.", "The parameter is the annotation type (i.e. careful, translation)."); var type = annotationType.ToString().ToLower(); if (_synchInvoke.InvokeRequired) { _synchInvoke.Invoke((Action)(() => ErrorReport.NotifyUserOfProblem(_srcRecStreamProvider.Error, msg, type)), null); } else { ErrorReport.NotifyUserOfProblem(_srcRecStreamProvider.Error, msg, type); } } return(provider); }
private void LoadNativeStorage(object invokeUntyped) { try { nativeStorage = NativeStorage.LoadFromAssemblyPath(); } catch (Exception ex) { // Need to swallow this unfortunately because we are on a backrground thread Debug.Fail(ex.Message); } finally { if (nativeStorage == null) { nativeStorage = new NativeStorage(); } } // Ping the UI to let in know the Database is now loaded ISynchronizeInvoke invoke = (ISynchronizeInvoke)invokeUntyped; try { WaitCallback del = delegate(object notused) { this.OnTabPageChanged(this, EventArgs.Empty); }; invoke.Invoke(del, new object[] { null }); } catch (Exception) { // No need to assert. We get this if the user closes the application before // the database finishes loading } }
public void RaiseWheelOrPositionChanged() { EventHandler handler = wheelOrPositionChanged; if (null != handler) { foreach (EventHandler singleCast in handler.GetInvocationList()) { ISynchronizeInvoke syncInvoke = singleCast.Target as ISynchronizeInvoke; try { if ((null != syncInvoke) && (syncInvoke.InvokeRequired)) { syncInvoke.Invoke(singleCast, new object[] { this, EventArgs.Empty }); } else { singleCast(this, EventArgs.Empty); } } catch { } } } }
public void Invoke(T param) { Delegate d = Delegate.CreateDelegate(typeof(Action <T>), Target.Target, Method); try { ISynchronizeInvoke synchronizer = Target as ISynchronizeInvoke; if (synchronizer != null) { //Requires thread affinity if (synchronizer.InvokeRequired) { synchronizer.Invoke(d, new object[] { param }); return; } } if (d != null) { d.DynamicInvoke(param); } } catch (Exception e) { //TODO: domain logging. } }
/// <summary> /// Raises the <see cref="E:WorkingThreadFinished"/> event. /// </summary> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> /// <remarks>Documented by Dev02, 2008-05-20</remarks> public static void OnWorkingThreadFinished(EventArgs e) { EventHandler handler = WorkingThreadFinished; if (handler != null) { foreach (EventHandler caster in handler.GetInvocationList()) { ISynchronizeInvoke SyncInvoke = caster.Target as ISynchronizeInvoke; try { if (SyncInvoke != null && SyncInvoke.InvokeRequired) { SyncInvoke.Invoke(handler, new object[] { null, e }); } else { caster(null, e); } } catch { } } } }
/// <summary> /// Fires the specified event, and passes the input as a parameter. /// </summary> /// <typeparam name="T">Type of the input parameter.</typeparam> /// <param name="eventToFire">The event to fire.</param> /// <param name="input">The input.</param> public static void FireEvent <T>(Delegate eventToFire, object sender, T input) { #if PocketPC throw new NotImplementedException(); #else if (eventToFire != null) { foreach (Delegate singleCast in eventToFire.GetInvocationList()) { ISynchronizeInvoke syncInvoke = singleCast.Target as ISynchronizeInvoke; try { if (syncInvoke != null && syncInvoke.InvokeRequired) { syncInvoke.Invoke(eventToFire, new object[] { sender, input }); } else { singleCast.DynamicInvoke(new object[] { sender, input }); } } catch { } } } #endif }
/// <summary> /// Invokes the specified action on the thread that the specified sync object was created on. /// </summary> public static void Invoke(ISynchronizeInvoke sync, Action action) { if (!sync.InvokeRequired) { action(); } else { object[] args = new object[] { }; sync.Invoke(action, args); } }
/// <summary> /// Invoke the given delegate on the given syncronizer. /// </summary> public static void Invoke(ISynchronizeInvoke syncronizer, Action method) { if (syncronizer != null && syncronizer.InvokeRequired) { Action exceptionLogger = () => { try { method.DynamicInvoke(); } catch (Exception e) { log.Error("Exception in Invoke", e); throw; } }; syncronizer.Invoke(exceptionLogger, new object[0]); } else { method(); } }
public static void SetProperty(ISynchronizeInvoke context, string key, object value) { context.Invoke(DelegateSetProperty, new Object[] { context, key, value }); }
public static object GetProperty(ISynchronizeInvoke context, string key) { return context.Invoke(DelegateGetProperty, new Object[] {context, key} ); }