void EqualDelegateTest() { dynamic d = this; // Assert (d == delegate { }, true, "#1"); EmptyDelegate b = EqualDelegateTest; d = b; //Assert (d == EqualDelegateTest, true, "#2"); /* * * void EqualTestDelegate_2 () * { * EmptyDelegate ed = delegate () {}; * * Expression<Func<EmptyDelegate, EmptyDelegate, bool>> e2 = (a, b) => a == b; * AssertNodeType (e2, ExpressionType.Equal); * Assert (false, e2.Compile ().Invoke (delegate () {}, null)); * Assert (false, e2.Compile ().Invoke (delegate () {}, delegate {})); * Assert (false, e2.Compile ().Invoke (ed, delegate {})); * Assert (true, e2.Compile ().Invoke (ed, ed)); */ }
private void Window_Loaded(object sender, RoutedEventArgs e) { // Make sure we draw properly EmptyDelegate waitForRender = DoNotingFunc; Dispatcher.Invoke(waitForRender, System.Windows.Threading.DispatcherPriority.Background); }
public IEnumerable <PcapFrame> PacketEnumerator(EmptyDelegate waitFunction, StreamReadCompletedCallback captureCompleteCallback) { const int MIN_TAKE_TIMEOUT = 100; int timeoutMilliSecs = MIN_TAKE_TIMEOUT; var cancellationToken = this.backgroundStreamReaderCanceller.Token; //int maxSleepMS = (int)Math.Sqrt(2.0 * this.readTimeoutMilliseconds);//200*200/2 = 20.000 = 20 seconds //maxSleepMS += timeoutMilliSecs;//to make sure BlockingRead timeouts before int maxSleepMS = (int)Math.Sqrt(2.0 * this.readTimeoutMilliseconds + timeoutMilliSecs * timeoutMilliSecs); while (!cancellationToken.IsCancellationRequested && (/*this.backgroundStreamReader.IsBusy ||*/ !this.EndOfStream() || this.packetQueue.Count > 0)) { /* * if(this.packetQueue.Count>0) { * sleepMilliSecs = 20; * PcapFrame packet; * lock(this.packetQueue) { * packet=this.packetQueue.Dequeue(); * } * this.dequeuedByteCount+=packet.Data.Length; * if (this.packetQueue.Count < this.packetQueueMaxSize / 2) * this.packetQueueHasRoomEvent.Set(); * yield return packet; * } * else { * if (sleepMilliSecs++ > maxSleepMS) {//200*200/2 = 20.000 = 20 seconds * //abort the reading, something has gone wrong... * yield break; * } * if (waitFunction != null) * waitFunction(); * else { * //This works in .NET 4.5 and .NET Standard: * System.Threading.Tasks.Task.Delay(sleepMilliSecs).Wait(); * * //This works in .NET 4.0 * //System.Threading.Thread.Sleep(sleepMilliSecs); * * } * } */ if (this.packetQueue.TryTake(out PcapFrame packet, timeoutMilliSecs, cancellationToken)) { timeoutMilliSecs = MIN_TAKE_TIMEOUT; this.dequeuedByteCount += packet.Data.Length; yield return(packet); } else { if (timeoutMilliSecs++ > maxSleepMS) //20 seconds of total waiting time since last Take/Dequeue //abort the reading, something has gone wrong... { yield break; } waitFunction?.Invoke(); } } //yield break; }
public MainFormPhoneLineControl( ICore core, int line, KryptonCheckButton controlButton, Control controlCallerName, Control controlCallerNumber, Control controlDuration, Control controlCallState, KryptonCheckButton holdButton ) { _callOnDurationChanged = Call_OnDurationChanged; _callOnInfoChanged = Call_OnInfoChanged; _callOnStateChanged = Call_OnStateChanged; _callOnRemoved = Call_OnRemoved; _core = core; Line = line; ControlButton = controlButton; _controlCallerName = controlCallerName; _controlCallerNumber = controlCallerNumber; _controlDuration = controlDuration; _controlCallState = controlCallState; _holdButton = holdButton; _controlCallerNumber.TextChanged += _controlCallerNumber_TextChanged; RefreshBackUI(); }
private void Search() { if (pnlResults.InvokeRequired) { EmptyDelegate ed = new EmptyDelegate(Search); Invoke(ed); } else { eligibility_data ed = new eligibility_data(); DataTable matches = ed.Search(BuildSQL()); DateTime? lastDate = new DateTime(1900, 1, 1); numAppointmentsFound = matches.Rows.Count; pnlResults.SuspendLayout(); pnlResults.Controls.Clear(); foreach (DataRow aRow in matches.Rows) { ed = new eligibility_data(); ed.Load(aRow); AddAppointment(ed, lastDate); lastDate = ed.appt_date; } pnlResults.ResumeLayout(); UpdateLastLabelSafe(lastDateLabel, numAppointmentsCurrentDate); UpdateBinCounts(); } }
public IEnumerable <PcapPacket> PacketEnumerator(EmptyDelegate waitFunction, ReadCompletedCallback captureCompleteCallback) { while (!this.backgroundFileReader.CancellationPending && (this.backgroundFileReader.IsBusy || fileStream.Position + 1 < fileStream.Length || this.packetQueue.Count > 0)) { //loops++; if (this.packetQueue.Count > 0) { PcapPacket packet; lock (this.packetQueue) { packet = this.packetQueue.Dequeue(); } this.dequeuedByteCount += packet.Data.Length; yield return(packet); } else { if (waitFunction == null) { System.Threading.Thread.Sleep(20); } else { waitFunction(); } } } //yield break; }
public static void Update(ref ulong Alarm, EmptyDelegate Callback, uint DelayInMsec, bool SeparateThread) { if (Alarm != NULL_ALARM) { doSyncAction(ActionType.RemoveNoUpdate, Alarm, null); } Alarm = Delay(Callback, DelayInMsec, SeparateThread); }
protected void Autoescape(TemplateContext Context, dynamic Expression, EmptyDelegate Block) { bool OldAutoescape = Context.Autoescape; Context.Autoescape = Expression; { Block(); } Context.Autoescape = OldAutoescape; }
protected void Autoescape(TemplateContext Context, dynamic Expression, EmptyDelegate Block) { bool OldAutoescape = Context.Autoescape; Context.Autoescape = Expression; { Block(); } Context.Autoescape = OldAutoescape; }
public WaitDlg() { InitializeComponent(); Show(); // Make sure we draw properly EmptyDelegate waitForRender = DoNotingFunc; Dispatcher.Invoke(waitForRender, System.Windows.Threading.DispatcherPriority.Background); }
private void StandardInitialization() { InitializeComponent(); updateMainLabel = new UpdateLabelDelegate(UpdateMainLabel); updateProgressBar = new UpdateProgressBarDelegate(UpdateProgressBar); updateBottomBar = new UpdateLabelDelegate(UpdateBottomBar); uploadFiles = new EmptyDelegate(StartFileUploadThreadSafe); CloseOnComplete = true; formTimer.AutoReset = false; formTimer.Elapsed += formTimer_Elapsed; }
private void SafeRaiseEvent(EmptyDelegate del) { if (del == null) { return; } var invocationList = del.GetInvocationList(); foreach (var current in invocationList) { ((EmptyDelegate)current).BeginInvoke(_emptyDelegateAsyncCallback, current); } }
private void ImportTouchup() { if (lblMaxResults.InvokeRequired) { EmptyDelegate d = new EmptyDelegate(ImportTouchup); Invoke(d); } else { pnlTop.Enabled = true; btnCheckEligibility.Enabled = true; Search(); pnlLoading.Visible = false; } }
public IEnumerable <PcapFrame> PacketEnumerator(EmptyDelegate waitFunction, StreamReadCompletedCallback captureCompleteCallback) { int sleepMilliSecs = 20; var cancellationToken = this.backgroundStreamReaderCanceller.Token; int maxSleepMS = (int)Math.Sqrt(2.0 * this.readTimeoutMilliseconds); //200*200/2 = 20.000 = 20 seconds maxSleepMS += sleepMilliSecs; //to make sure BlockingRead timeouts before while (!cancellationToken.IsCancellationRequested && (/*this.backgroundStreamReader.IsBusy ||*/ !this.EndOfStream() || this.packetQueue.Count > 0)) { if (this.packetQueue.Count > 0) { sleepMilliSecs = 20; PcapFrame packet; lock (this.packetQueue) { packet = this.packetQueue.Dequeue(); } this.dequeuedByteCount += packet.Data.Length; if (this.packetQueue.Count < this.packetQueueMaxSize / 2) { this.packetQueueHasRoomEvent.Set(); } yield return(packet); } else { if (sleepMilliSecs++ > maxSleepMS) //200*200/2 = 20.000 = 20 seconds //abort the reading, something has gone wrong... { yield break; } if (waitFunction != null) { waitFunction(); } else { //This works in .NET 4.5 and .NET Standard: System.Threading.Tasks.Task.Delay(sleepMilliSecs).Wait(); //This works in .NET 4.0 //System.Threading.Thread.Sleep(sleepMilliSecs); } } } //yield break; }
public void Start(int advanceCount) { if (advanceCount > 0) { EmptyDelegate nextDelegate = new EmptyDelegate(Next); while (advanceCount-- > 0) { Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, nextDelegate); Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, nextDelegate); } } else if (fActivePanel.PanelState == PanelState.Paused) { fActivePanel.UnPause(); } }
public static void TryActionHelper(EmptyDelegate method, int retryCount) { bool retry = false; do { try { method.Invoke(); retry = false; } catch (Exception ex) { retry = (--retryCount) > 0 ? true : false; } } while (retry); }
public static ulong Delay(EmptyDelegate Callback, uint DelayInMsec, bool SeparateThread) { ulong alarm = ticks + (ulong)(DelayInMsec / msecPerTick) + 2; // separate threads have even tick counts if (SeparateThread) { alarm &= MASK_LONG; } else { alarm |= 0x01; } return(doSyncAction(ActionType.Add, alarm, Callback)); }
public static void TryActionHelper(EmptyDelegate method, int retryCount) { bool retry = false; do { try { method.Invoke(); retry = false; } catch (Exception ex) { retry = (--retryCount) > 0 ? true : false; Console.WriteLine(ex.Message); } } while (retry); }
private void UpdateBinCounts() { if (btnTomorrow.InvokeRequired) { EmptyDelegate ed = new EmptyDelegate(UpdateBinCounts); Invoke(ed); } else { eligibility_data ed = new eligibility_data(); UpdateBinCount(ed.Search(BuildSQL(true, FormSearchMode.Unsent)).Rows[0][0].ToString(), btnUnverified, "Unsent", _searchMode == FormSearchMode.Unsent); UpdateBinCount(ed.Search(BuildSQL(true, FormSearchMode.Rejected)).Rows[0][0].ToString(), btnRejected, "Rejected", _searchMode == FormSearchMode.Rejected); UpdateBinCount(ed.Search(BuildSQL(true, FormSearchMode.Tomorrow)).Rows[0][0].ToString(), btnTomorrow, "Tomorrow", _searchMode == FormSearchMode.Tomorrow); UpdateBinCount(ed.Search(BuildSQL(true, FormSearchMode.AllUpcoming)).Rows[0][0].ToString(), btnUpcoming, "All Upcoming", _searchMode == FormSearchMode.AllUpcoming); UpdateBinCount(ed.Search(BuildSQL(true, FormSearchMode.Sent)).Rows[0][0].ToString(), btnSent, "Sent", _searchMode == FormSearchMode.Sent); } }
public IEnumerable <PcapFrame> PacketEnumerator(EmptyDelegate waitFunction, StreamReadCompletedCallback captureCompleteCallback) { int sleepMilliSecs = 20; int maxSleepMS = (int)Math.Sqrt(2.0 * this.readTimeoutMilliseconds); //200*200/2 = 20.000 = 20 seconds maxSleepMS += sleepMilliSecs; //to make sure BlockingRead timeouts before while (!this.backgroundStreamReader.CancellationPending && (this.backgroundStreamReader.IsBusy || !this.EndOfStream() || this.packetQueue.Count > 0)) { if (this.packetQueue.Count > 0) { sleepMilliSecs = 20; PcapFrame packet; lock (this.packetQueue) { packet = this.packetQueue.Dequeue(); } this.dequeuedByteCount += packet.Data.Length; yield return(packet); } else { if (sleepMilliSecs++ > maxSleepMS) //200*200/2 = 20.000 = 20 seconds //abort the reading, something has gone wrong... { yield break; } if (waitFunction != null) { waitFunction(); } else { System.Threading.Thread.Sleep(sleepMilliSecs); } } } //yield break; }
private void TickTimer() { if (InvokeRequired) { EmptyDelegate ed = new EmptyDelegate(TickTimer); Invoke(ed); } else { string callMinutesDisplay; if (callTime.Minutes > 10) { callMinutesDisplay = callTime.Minutes.ToString(); } else { callMinutesDisplay = "0" + callTime.Minutes; } string callSecondsDisplay; int callSeconds; callSeconds = callTime.Seconds % 60; if (callSeconds > 10) { callSecondsDisplay = callSeconds.ToString(); } else { callSecondsDisplay = "0" + callSeconds; } Text = "Multiple Claim Call: " + callMinutesDisplay + ":" + callSecondsDisplay; } }
private void UpdateForm() { if (InvokeRequired) { EmptyDelegate d = new EmptyDelegate(UpdateForm); Invoke(d, null); } else { if (_error != string.Empty) MessageBox.Show(_error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); else { textBoxGetAdrH.Text = GetHex(_getData[0]); textBoxGetLenH.Text = GetHex(_getData[1]); if (_setCmd == 0) textBoxGetDatH.Text = System.Text.Encoding.ASCII.GetString(_getData, 2, _getData.Length - 4); else { textBoxGetDatH.Text = ""; for (int i = 2; i < _getData.Length - 2; i++) textBoxGetDatH.Text += GetHex(_getData[i]) + " "; } textBoxGetCRCH.Text = GetHex(_getData[_getData.Length - 1]) + " " + GetHex(_getData[_getData.Length - 2]); } Text = string.Format("Test FTDI ({0})", _counter); Update(); } }
private static ulong doSyncAction(ActionType Type, ulong Tick, EmptyDelegate Callback) { bool separateThread = false; lock (llock) { switch (Type) { case ActionType.Add: while (pendingCallbacks.ContainsKey(Tick)) { Tick += 2; } pendingCallbacks.Add(Tick, Callback); updateNextCallback(); return(Tick); case ActionType.Remove: if (pendingCallbacks.ContainsKey(Tick)) { pendingCallbacks.Remove(Tick); updateNextCallback(); } return(0); case ActionType.RemoveNoUpdate: if (pendingCallbacks.ContainsKey(Tick)) { pendingCallbacks.Remove(Tick); } break; case ActionType.Invoke: if (pendingCallbacks.ContainsKey(nextCallback)) { ulong key = nextCallback; Callback = pendingCallbacks[key]; RemoveAlarm(key); separateThread = ((key & 0x01) == 0); } else { updateNextCallback(); return(0); } break; default: return(0); } } if (Type == ActionType.Invoke) { if (separateThread) { Thread t = new Thread(new ThreadStart(Callback)); t.IsBackground = true; t.Priority = ThreadPriority.BelowNormal; t.Start(); } else { Callback(); } } return(0); }
static void Closure(EmptyDelegate x) { }
public void Add(EmptyDelegate a) { lock (_callbacks) { _callbacks.Add(a); } }
public void UnregisterHealedListener(EmptyDelegate del) { OnHealed -= del; }
public override void CreateView(EquipmentSlot dataSource) { base.CreateView(dataSource); trigger += dataSource.OnTrigger; itemSlot.text = dataSource.slot.ToString(); }
public void UnregisterUpdateListener(EmptyDelegate del) { OnUpdate -= del; }
public void AddTable() { EmptyDelegate updTables = UpdateTablesList; _windowManager.ShowWindow(new AddTableViewModel(_windowManager, updTables)); }
protected void Foreach(TemplateContext Context, String VarName, dynamic Expression, EmptyDelegate Iteration, EmptyDelegate Else = null) { int Index = 0; foreach (var Item in DynamicUtils.ConvertToIEnumerable(Expression)) { Context.SetVar("loop", new Dictionary <String, dynamic> { { "index", Index + 1 }, { "index0", Index }, }); Context.SetVar(VarName, Item); Iteration(); Index++; } if (Index == 0) { if (Else != null) { Else(); } } }
/// <summary> /// Execute the specified delegate in the context of the UI /// asynchronously. /// </summary> public static void ExecInUI(EmptyDelegate d) { ExecInUI(d, null); }
public AsynchronousActivity() { asyncDelegate = new EmptyDelegate(OnAsyncWork); }
static void Main(string[] args) { Converter converter = new Converter(); Int2StringDelegate del = new Int2StringDelegate(converter.ConvertToString); //variabile di tipo implicito var del2 = new Int2StringDelegate(converter.ConvertToString); //creazione implicita delegate Int2StringDelegate isdel = converter.ConvertToString; Int2StringDelegate del3 = (Int2StringDelegate)Delegate.CreateDelegate(typeof(Int2StringDelegate), converter, "ConvertToString"); del3(123); string str = isdel(123); str = isdel.Invoke(123); //ottenere informazioni Console.WriteLine("ottenere informazioni sul delegate"); var method = isdel.Method; Console.WriteLine(method.Name); var target = isdel.Target; Console.WriteLine(target.ToString()); Console.WriteLine("ottenere informazioni sul delegate con metodo statico"); isdel = Converter.StaticConvertToString; Console.WriteLine(isdel.Method); Console.WriteLine(isdel.Target); UseDelegate(Converter.StaticConvertToString, 1, 2, 3); EmptyDelegate multicast = Metodo1; multicast += Metodo2; multicast += Metodo2; //un metodo può essere aggiunto più volte multicast(); multicast -= Metodo2; Delegate[] list = multicast.GetInvocationList(); foreach (Delegate delInstance in list) { Console.WriteLine("invoco {0}", delInstance.Method); (delInstance as EmptyDelegate).Invoke(); //delInstance.DynamicInvoke(); } multicast = (EmptyDelegate)Delegate.Combine(new EmptyDelegate(Metodo1), new EmptyDelegate(Metodo2)); multicast -= Metodo1; multicast -= Metodo2; if (multicast != null) { multicast.Invoke(); } Int2StringDelegate multi = converter.ConvertToString; multi += converter.RaddoppiaNumero; Console.WriteLine(multi(10)); int x = 1; RefDelegate multiref = Raddoppia; multiref += Triplica; multiref(ref x); Console.WriteLine(x); ConvertOriginToDest <int, string> siconvert = converter.StringToInt; int i = siconvert("123"); ConvertOriginToDest <string, int> isconvert = converter.Int2String; string s = isconvert(123); Func <int, int> func = Fattoriale; int n = EvaluateFunction <int>(func, 10); Func <double, double> funcRadice = Math.Sqrt; double radice = EvaluateFunction <double>(funcRadice, 144); double log = EvaluateFunction(Math.Log10, 100.0); //stampo l'errore OperazionePericolosa(PrintError); //covarianza func Func <string> funcHello = Hello; Func <object> funcObj = funcHello; object obj = funcObj(); //controvarianza Action Action <object> actObj = UseObject; Action <string> actStr = actObj; actStr("Hello"); }
private void UpdateStatus() { if (InvokeRequired) { EmptyDelegate d = new EmptyDelegate(UpdateStatus); Invoke(d, null); } else { btnStart.Enabled = _isStop; btnStop.Enabled = !_isStop; groupBox1.Enabled = _isStop; if (_isExit) Close(); } }
public AsynchronousActivity() { asyncDelegate = new EmptyDelegate(OnAsyncWork); }
async protected Task ForeachAsync(TemplateContext Context, String VarName, dynamic Expression, EmptyDelegate Iteration, EmptyDelegate Else = null) { int Index = 0; foreach (var Item in DynamicUtils.ConvertToIEnumerable(Expression)) { Context.SetVar("loop", new Dictionary<String, dynamic> { { "index", Index + 1 }, { "index0", Index }, }); Context.SetVar(VarName, Item); await Iteration(); Index++; } if (Index == 0) { if (Else != null) await Else(); } }
protected void StartAsycWaitFunction(EmptyDelegate function) { asyncWaitThread = new Thread(new ThreadStart(function)); asyncWaitThread.Start(); }
public void UnregisterDeleteListener(EmptyDelegate del) { OnDelete -= del; }