private void MoveUnitTo(Field field) { if (field.IsEmpty()) { // Move Field oldField = unitHeld.field; unitHeld.field = null; unitHeld.Summon(field); oldField.unit = null; } else { // Switch Unit otherUnit = field.unit; Field tmpField = unitHeld.field; unitHeld.field = otherUnit.field; unitHeld.transform.position = otherUnit.transform.position; otherUnit.field.unit = unitHeld; otherUnit.field = tmpField; otherUnit.transform.position = tmpField.transform.position; tmpField.unit = otherUnit; } OnUnitsUpdated?.Invoke(); }
public override void Start() { if (ThrowEventOnStart) { OnClickEvent.Invoke(); OnClick?.Invoke(); } }
public static void ReleaseEvents(bool Force) { count++; if (--holdLevel <= 0 || Force) { holdLevel = 0; if (numLinesChanged) { NumLinesChanged.Invoke(); numLinesChanged = false; } if (longestLinechanged) { LongestLineChanged.Invoke(); longestLinechanged = false; } if (documentChanged) { DocumentChanged.Invoke(); documentChanged = false; } else if (caretLocationChanged) { CaretLocationChanged.Invoke(); } else if (viewChanged) { ViewChanged.Invoke(); } caretLocationChanged = false; viewChanged = false; if (selectionChanged) { SelectionChanged.Invoke(); selectionChanged = false; } if (documentChangedChanged) { DocumentChangedChanged.Invoke(); documentChangedChanged = false; } } }
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 static void SetFont(Font Font) { if (Font.Size != fontSize || Font.Name != fontName) { fontSize = Font.Size; fontName = Font.Name; updateFonts(); if (FontMetricsChanged != null) { FontMetricsChanged.Invoke(); } } }
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 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); }
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"); }