System.Action.Invoke()

Here are the examples of the csharp api System.Action.Invoke() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

12579 Examples 7

19 Source : TerrariaHooksManager.cs
with MIT License
from 0x0ade

static void OnUnloadAll(Action orig) {
            orig();

            // Dispose the context.
            Dispose();
        }

19 Source : CelesteNetClientContext.cs
with MIT License
from 0x0ade

public override void Update(GameTime gameTime) {
            base.Update(gameTime);

            lock (MainThreadQueue)
                while (MainThreadQueue.Count > 0)
                    MainThreadQueue.Dequeue()();

            if (Started && !(Client?.IsAlive ?? true))
                Dispose();
        }

19 Source : CelesteNetClientContext.cs
with MIT License
from 0x0ade

protected void RunOnMainThread(Action action, bool wait = false) {
            if (Thread.CurrentThread == MainThreadHelper.MainThread) {
                action();
                return;
            }

            using ManualResetEvent waiter = wait ? new ManualResetEvent(false) : null;
            if (wait) {
                Action real = action;
                action = () => {
                    try {
                        real();
                    } finally {
                        waiter.Set();
                    }
                };
            }

            lock (MainThreadQueue)
                MainThreadQueue.Enqueue(action);

            if (wait)
                WaitHandle.WaitAny(new WaitHandle[] { waiter });
        }

19 Source : DataContext.cs
with MIT License
from 0x0ade

public Action WaitFor<T>(int timeout, DataFilter<T> cb, Action? cbTimeout = null) where T : DataType<T> {
            object key = new();

            DataHandler? wrap = null;
            wrap = RegisterHandler<T>((con, data) => {
                lock (key) {
                    if (wrap == null || !cb(con, data))
                        return;
                    UnregisterHandler(typeof(T), wrap);
                    wrap = null;
                }
            });

            if (timeout > 0)
                Task.Run(async () => {
                    await Task.Delay(timeout);
                    lock (key) {
                        if (wrap == null)
                            return;
                        try {
                            UnregisterHandler(typeof(T), wrap);
                            wrap = null;
                            cbTimeout?.Invoke();
                        } catch (Exception e) {
                            Logger.Log(LogLevel.CRI, "data", $"Error in WaitFor timeout callback:\n{typeof(T).FullName}\n{cb}\n{e}");
                        }
                    }
                });

            return () => UnregisterHandler(typeof(T), wrap);
        }

19 Source : DisposeActionStream.cs
with MIT License
from 0x0ade

public override void Close() {
            Action?.Invoke();
            Inner.Close();
        }

19 Source : DisposeActionStream.cs
with MIT License
from 0x0ade

protected override void Dispose(bool disposing) {
            Action?.Invoke();
            Inner.Dispose();
        }

19 Source : Maybe.cs
with MIT License
from 0x1000000

void IMaybe.Exit()
        {
            if (this._continuation == null)
            {
                this._forExit = true; //Sync
                return;
            }

            this._result = MaybeResult.Nothing();
            this.IsCompleted = true;

            if (this._parent != null)
            {
                this._parent.Exit();
            }
            else
            {
                this._continuation();
            }
        }

19 Source : Maybe.cs
with MIT License
from 0x1000000

internal void SetException(Exception exception)
        {
            this._exception = exception;
            this.IsCompleted = true;
            this._continuation?.Invoke();
        }

19 Source : Maybe.cs
with MIT License
from 0x1000000

private void NotifyResult(bool isNothing)
        {
            this.IsCompleted = true;
            if (isNothing)
            {
                this._parent.Exit();
            }
            else
            {
                this._continuation?.Invoke();
            }
        }

19 Source : MaybeEx.cs
with MIT License
from 0x1000000

public void OnCompleted(Action continuation)
        {
            if (this._continuation != null)
            {
                throw new Exception("Only one continuation is allowed");
            }

            if (this._result.HasValue)
            {
                continuation();
            }
            else
            {
                this._continuation = continuation;
            }
        }

19 Source : MaybeEx.cs
with MIT License
from 0x1000000

private void SetFinalContinuation(Action finalContinuation)
        {
            this._finalContinuation = finalContinuation;
            if (this.IsCompleted)
            {
                finalContinuation();
            }
        }

19 Source : MaybeEx.cs
with MIT License
from 0x1000000

private void CallContinuation()
        {
            this.IsCompleted = true;
            if (this._finalContinuation != null)
            {
                this._finalContinuation();
            }
            else
            {
                this._continuation?.Invoke();
            }
        }

19 Source : Reader.cs
with MIT License
from 0x1000000

public void OnCompleted(Action continuation)
        {
            if (this.IsCompleted)
            {
                continuation();
            }
            else
            {
                if (this._continuation != null)
                {
                    throw new Exception("Only a single async continuation is allowed");
                }
                this._continuation = continuation;
            }
        }

19 Source : Reader.cs
with MIT License
from 0x1000000

internal void SetResult(T result)
        {
            this._result = result;
            this.IsCompleted = true;
            this._continuation?.Invoke();
        }

19 Source : CommandExecuteMonitor.cs
with MIT License
from 1100100

private void SyncCommandExecuteMonitor(string methodName, string sql, object param, Action action)
        {
            var sw = Stopwatch.StartNew();
            try
            {
                action();
            }
            finally
            {
                sw.Stop();
                if (sw.ElapsedMilliseconds > MonitorConfiguration.SlowCriticalValue)
                {
                    SlowCommandNotification(methodName, sql, param, sw.ElapsedMilliseconds);
                }
            }
        }

19 Source : DisposableAction.cs
with MIT License
from 1100100

public void Dispose()
        {
            _action();
        }

19 Source : MetroColorPicker.xaml.cs
with MIT License
from 1217950746

private void Initialize(HsbaColor hsbaColor)
        {
            // 绑定主题
            Utility.Refresh(this);

            // 设置当前初始颜色
            currentColor = hsbaColor;
            // defaultColor = currentColor;

            // 界面初始化
            viewDefColor.Background = defaultColor.SolidColorBrush;
            viewLine1.Offset = 1.0 / 6.0 * 0.0;
            viewLine2.Offset = 1.0 / 6.0 * 1.0;
            viewLine3.Offset = 1.0 / 6.0 * 2.0;
            viewLine4.Offset = 1.0 / 6.0 * 3.0;
            viewLine5.Offset = 1.0 / 6.0 * 4.0;
            viewLine6.Offset = 1.0 / 6.0 * 5.0;
            viewLine7.Offset = 1.0 / 6.0 * 6.0;

            // 按钮事件
            bool start = true;
            button.Click += delegate
            {
                polygon.Margin = new Thickness(ActualWidth / 2 - 5, -5.0, 0.0, 0.0);
                popup.IsOpen = true;
                if (start)
                {
                    ApplyColor(currentColor);
                    start = false;
                }
            };
            popup.Closed += delegate { if (ColorPickerClosed != null) ColorPickerClosed(); };
            viewDefColor.Click += delegate { ApplyColor(new HsbaColor(viewDefColor.Background)); };
            hex.ButtonClick += delegate { Clipboard.SetText(hex.Text); };

            // 视图被改变事件
            thumbSB.ValueChange += delegate { if (thumbSB.IsDragging) ViewChange(); };
            thumbH.ValueChange += delegate { if (thumbH.IsDragging) ViewChange(); };
            thumbA.ValueChange += delegate { if (thumbA.IsDragging) ViewChange(); };

            // RGBA操作事件
            rgbaR.TextChanged += delegate { if (rgbaR.IsSelectionActive) RgbaChange(); };
            rgbaG.TextChanged += delegate { if (rgbaG.IsSelectionActive) RgbaChange(); };
            rgbaB.TextChanged += delegate { if (rgbaB.IsSelectionActive) RgbaChange(); };
            rgbaA.TextChanged += delegate { if (rgbaA.IsSelectionActive) RgbaChange(); };

            // HSBA操作事件
            hsbaH.TextChanged += delegate { if (hsbaH.IsSelectionActive) HsbaChange(); };
            hsbaS.TextChanged += delegate { if (hsbaS.IsSelectionActive) HsbaChange(); };
            hsbaB.TextChanged += delegate { if (hsbaB.IsSelectionActive) HsbaChange(); };
            hsbaA.TextChanged += delegate { if (hsbaA.IsSelectionActive) HsbaChange(); };

            // HEX操作事件
            hex.TextChanged += delegate { if (hex.IsSelectionActive) HexChange(); };
        }

19 Source : MetroRichTextBox.cs
with MIT License
from 1217950746

public void AddLine(string content, RgbaColor rgba, Action action)
        {
            Run run = new Run(content);
            if (action == null)
            {
                if (rgba != null) { run.Foreground = rgba.SolidColorBrush; }
                Doreplacedent.Blocks.Add(new Paragraph(run));
            }
            else
            {
                Hyperlink hl = new Hyperlink(run);
                if (rgba != null) { hl.Foreground = rgba.SolidColorBrush; }
                hl.Click += delegate { action(); };
                hl.MouseLeftButtonDown += delegate { action(); };
                Doreplacedent.Blocks.Add(new Paragraph(hl));
            }
            ScrollToEnd();
        }

19 Source : MetroRichTextBox.cs
with MIT License
from 1217950746

public void AddLine(ImageSource image, Action action)
        {
            if (action == null)
            {
                Doreplacedent.Blocks.Add(new Paragraph(new InlineUIContainer(new MetroImage(image))));
            }
            else
            {
                Hyperlink hl = new Hyperlink(new InlineUIContainer(new MetroImage(image)));
                hl.Foreground = null;
                hl.Click += delegate { action(); };
                hl.MouseLeftButtonDown += delegate { action(); };
                Doreplacedent.Blocks.Add(new Paragraph(hl));
            }
            ScrollToEnd();
        }

19 Source : MetroRichTextBox.cs
with MIT License
from 1217950746

public void Add(string content, RgbaColor rgba, Action action)
        {
            if (Doreplacedent.Blocks.Count <= 0)
            {
                Doreplacedent.Blocks.Add(new Paragraph());
            }
            Run run = new Run(content);
            if (action == null)
            {
                if (rgba != null) { run.Foreground = rgba.SolidColorBrush; }
                (Doreplacedent.Blocks.LastBlock as Paragraph).Inlines.Add(run);
            }
            else
            {
                Hyperlink hl = new Hyperlink(run);
                if (rgba != null) { hl.Foreground = rgba.SolidColorBrush; }
                hl.Click += delegate { action(); };
                hl.MouseLeftButtonDown += delegate { action(); };
                (Doreplacedent.Blocks.LastBlock as Paragraph).Inlines.Add(hl);
            }
            ScrollToEnd();
        }

19 Source : MetroRichTextBox.cs
with MIT License
from 1217950746

public void Add(ImageSource image, Action action)
        {
            if (Doreplacedent.Blocks.Count <= 0)
            {
                Doreplacedent.Blocks.Add(new Paragraph());
            }
            if (action == null)
            {
                (Doreplacedent.Blocks.LastBlock as Paragraph).Inlines.Add(new InlineUIContainer(new MetroImage(image)));
            }
            else
            {
                Hyperlink hl = new Hyperlink(new InlineUIContainer(new MetroImage(image)));
                hl.Foreground = null;
                hl.Click += delegate { action(); };
                hl.MouseLeftButtonDown += delegate { action(); };
                (Doreplacedent.Blocks.LastBlock as Paragraph).Inlines.Add(hl);
            }
            ScrollToEnd();
        }

19 Source : DbBuilder.cs
with MIT License
from 17MKH

public void Build()
    {
        if (Options.Provider != DbProvider.Sqlite)
            Check.NotNull(Options.ConnectionString, "连接字符串未配置");

        //创建数据库上下文
        CreateDbContext();

        //加载仓储
        LoadRepositories();

        //执行自定义委托
        foreach (var action in _actions)
        {
            action.Invoke();
        }
    }

19 Source : VerifyHelper.cs
with MIT License
from 1996v

public static void IsSafeAction(Action testCode)
        {
            testCode();
        }

19 Source : VerifyHelper.cs
with MIT License
from 1996v

public static void Throws<T>(Action testCode, Func<T, bool> ex) where T : Exception
        {
            try
            {
                testCode();
            }
            catch (T t)
            {
                if (ex(t) == false)
                    throw new Exception("Different exception information", t);
                return;
            }
            catch
            {
                throw;
            }
            throw new Exception("No exception");
        }

19 Source : VerifyHelper.cs
with MIT License
from 1996v

public static void Throws<T>(Action testCode) where T : Exception
        {
            try
            {
                testCode();
            }
            catch (T)
            {
                return;
            }
            catch
            {
                throw;
            }
            throw new Exception("No exception");
        }

19 Source : G_CUIColorPicker.cs
with MIT License
from 1ZouLTReX1

private void Setup( Color inputColor )
        {
            alphaSlider.value = inputColor.a;
            alphaSliderBGImage.color = inputColor;
            
            var satvalGO = GO( "SaturationValue" );
            var satvalKnob = GO( "SaturationValue/Knob" );
            var hueGO = GO( "Hue" );
            var hueKnob = GO( "Hue/Knob" );
            var result = GO( "Result" );
            var hueColors = new Color [] 
            {
                Color.red,
                Color.yellow,
                Color.green,
                Color.cyan,
                Color.blue,
                Color.magenta,
            };
            
            var satvalColors = new Color [] 
            {
                new Color( 0, 0, 0 ),
                new Color( 0, 0, 0 ),
                new Color( 1, 1, 1 ),
                hueColors[0],
            };
            
            var hueTex = new Texture2D( 1, 7 );
            
            for ( int i = 0; i < 7; i++ ) {
                hueTex.SetPixel( 0, i, hueColors[i % 6] );
            }
            
            hueTex.Apply();
            hueGO.GetComponent<Image>().sprite = Sprite.Create( hueTex, new Rect( 0, 0.5f, 1, 6 ), new Vector2( 0.5f, 0.5f ) );
            var hueSz = GetWidgetSize( hueGO );
            var satvalTex = new Texture2D(2,2);
            satvalGO.GetComponent<Image>().sprite = Sprite.Create( satvalTex, new Rect( 0.5f, 0.5f, 1, 1 ), new Vector2( 0.5f, 0.5f ) );

            System.Action resetSatValTexture = () => {
                for ( int j = 0; j < 2; j++ ) {
                    for ( int i = 0; i < 2; i++ ) {
                        satvalTex.SetPixel( i, j, satvalColors[i + j * 2] );
                    }
                }
                satvalTex.Apply();
            };
            
            var satvalSz = GetWidgetSize( satvalGO );
            float Hue, Saturation, Value;
            RGBToHSV( inputColor, out Hue, out Saturation, out Value );

            System.Action applyHue = () => 
            {
                var i0 = Mathf.Clamp( ( int )Hue, 0, 5 );
                var i1 = ( i0 + 1 ) % 6;
                var resultColor = Color.Lerp( hueColors[i0], hueColors[i1], Hue - i0 );
                satvalColors[3] = resultColor;
                resetSatValTexture();
            };

            System.Action applySaturationValue = () => 
            {
                var sv = new Vector2( Saturation, Value );
                var isv = new Vector2( 1 - sv.x, 1 - sv.y );
                var c0 = isv.x * isv.y * satvalColors[0];
                var c1 = sv.x * isv.y * satvalColors[1];
                var c2 = isv.x * sv.y * satvalColors[2];
                var c3 = sv.x * sv.y * satvalColors[3];
                var resultColor = c0 + c1 + c2 + c3;
                var resImg = result.GetComponent<Image>();
                resImg.color = resultColor;
                if ( _color != resultColor )
                {
                    resultColor = new Color(resultColor.r, resultColor.g, resultColor.b, alphaSlider.value);
                    
                    if ( _onValueChange != null ) 
                    {
                        _onValueChange( resultColor );
                    }
                    _color = resultColor;
                    
                    alphaSliderBGImage.color = _color;
                }
            };
            applyHue();
            applySaturationValue();
            satvalKnob.transform.localPosition = new Vector2( Saturation * satvalSz.x, Value * satvalSz.y );
            hueKnob.transform.localPosition = new Vector2( hueKnob.transform.localPosition.x, Hue / 6 * satvalSz.y );
            System.Action dragH = null;
            System.Action dragSV = null;
            System.Action idle = () => {
                if ( Input.GetMouseButtonDown( 0 ) ) {
                    Vector2 mp;
                    if ( GetLocalMouse( hueGO, out mp ) ) {
                        _update = dragH;
                    } else if ( GetLocalMouse( satvalGO, out mp ) ) {
                        _update = dragSV;
                    }
                }
            };
            dragH = () => {
                Vector2 mp;
                GetLocalMouse( hueGO, out mp );
                Hue = mp.y / hueSz.y * 6;
                applyHue();
                applySaturationValue();
                hueKnob.transform.localPosition = new Vector2( hueKnob.transform.localPosition.x, mp.y );
                if ( Input.GetMouseButtonUp( 0 ) ) {
                    _update = idle;
                }
            };
            dragSV = () => {
                Vector2 mp;
                GetLocalMouse( satvalGO, out mp );
                Saturation = mp.x / satvalSz.x;
                Value = mp.y / satvalSz.y;
                applySaturationValue();
                satvalKnob.transform.localPosition = mp;
                if ( Input.GetMouseButtonUp( 0 ) ) {
                    _update = idle;
                }
            };
            _update = idle;
        }

19 Source : G_CUIColorPicker.cs
with MIT License
from 1ZouLTReX1

void Update()
        {
            if (_update != null) { _update(); }
        }

19 Source : UnityThread.cs
with MIT License
from 1ZouLTReX1

public void Update()
    {
        if (noActionQueueToExecuteUpdateFunc)
        {
            return;
        }

        //Clear the old actions from the actionCopiedQueueUpdateFunc queue
        actionCopiedQueueUpdateFunc.Clear();
        lock (actionQueuesUpdateFunc)
        {
            //Copy actionQueuesUpdateFunc to the actionCopiedQueueUpdateFunc variable
            actionCopiedQueueUpdateFunc.AddRange(actionQueuesUpdateFunc);
            //Now clear the actionQueuesUpdateFunc since we've done copying it
            actionQueuesUpdateFunc.Clear();
            noActionQueueToExecuteUpdateFunc = true;
        }

        // Loop and execute the functions from the actionCopiedQueueUpdateFunc
        for (int i = 0; i < actionCopiedQueueUpdateFunc.Count; i++)
        {
            actionCopiedQueueUpdateFunc[i].Invoke();
        }
    }

19 Source : UnityThread.cs
with MIT License
from 1ZouLTReX1

public void LateUpdate()
    {
        if (noActionQueueToExecuteLateUpdateFunc)
        {
            return;
        }

        //Clear the old actions from the actionCopiedQueueLateUpdateFunc queue
        actionCopiedQueueLateUpdateFunc.Clear();
        lock (actionQueuesLateUpdateFunc)
        {
            //Copy actionQueuesLateUpdateFunc to the actionCopiedQueueLateUpdateFunc variable
            actionCopiedQueueLateUpdateFunc.AddRange(actionQueuesLateUpdateFunc);
            //Now clear the actionQueuesLateUpdateFunc since we've done copying it
            actionQueuesLateUpdateFunc.Clear();
            noActionQueueToExecuteLateUpdateFunc = true;
        }

        // Loop and execute the functions from the actionCopiedQueueLateUpdateFunc
        for (int i = 0; i < actionCopiedQueueLateUpdateFunc.Count; i++)
        {
            actionCopiedQueueLateUpdateFunc[i].Invoke();
        }
    }

19 Source : UnityThread.cs
with MIT License
from 1ZouLTReX1

public void FixedUpdate()
    {
        if (noActionQueueToExecuteFixedUpdateFunc)
        {
            return;
        }

        //Clear the old actions from the actionCopiedQueueFixedUpdateFunc queue
        actionCopiedQueueFixedUpdateFunc.Clear();
        lock (actionQueuesFixedUpdateFunc)
        {
            //Copy actionQueuesFixedUpdateFunc to the actionCopiedQueueFixedUpdateFunc variable
            actionCopiedQueueFixedUpdateFunc.AddRange(actionQueuesFixedUpdateFunc);
            //Now clear the actionQueuesFixedUpdateFunc since we've done copying it
            actionQueuesFixedUpdateFunc.Clear();
            noActionQueueToExecuteFixedUpdateFunc = true;
        }

        // Loop and execute the functions from the actionCopiedQueueFixedUpdateFunc
        for (int i = 0; i < actionCopiedQueueFixedUpdateFunc.Count; i++)
        {
            actionCopiedQueueFixedUpdateFunc[i].Invoke();
        }
    }

19 Source : TempDisposable.cs
with MIT License
from 2881099

public void Dispose() => _release?.Invoke();

19 Source : SingleTempAdapter.cs
with MIT License
from 2881099

public override void Dispose()
            {
                _dispose?.Invoke();
            }

19 Source : DefaultRedisSocket.cs
with MIT License
from 2881099

public void Dispose() => _dispose?.Invoke();

19 Source : DbContextSync.cs
with MIT License
from 2881099

internal void ExecCommand() {
			if (isExecCommanding) return;
			if (_actions.Any() == false) return;
			isExecCommanding = true;

			ExecCommandInfo oldinfo = null;
			var states = new List<object>();

			Func<string, int> dbContextBetch = methodName => {
				if (_dicExecCommandDbContextBetch.TryGetValue(oldinfo.stateType, out var trydic) == false)
					trydic = new Dictionary<string, Func<object, object[], int>>();
				if (trydic.TryGetValue(methodName, out var tryfunc) == false) {
					var arrType = oldinfo.stateType.MakeArrayType();
					var dbsetType = oldinfo.dbSet.GetType().BaseType;
					var dbsetTypeMethod = dbsetType.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { arrType }, null);

					var returnTarget = Expression.Label(typeof(int));
					var parm1DbSet = Expression.Parameter(typeof(object));
					var parm2Vals = Expression.Parameter(typeof(object[]));
					var var1Vals = Expression.Variable(arrType);
					tryfunc = Expression.Lambda<Func<object, object[], int>>(Expression.Block(
						new[] { var1Vals },
						Expression.replacedign(var1Vals, Expression.Convert(global::FreeSql.Internal.Utils.GetDataReaderValueBlockExpression(arrType, parm2Vals), arrType)),
						Expression.Return(returnTarget, Expression.Call(Expression.Convert(parm1DbSet, dbsetType), dbsetTypeMethod, var1Vals)),
						Expression.Label(returnTarget, Expression.Default(typeof(int)))
					), new[] { parm1DbSet, parm2Vals }).Compile();
					trydic.Add(methodName, tryfunc);
				}
				return tryfunc(oldinfo.dbSet, states.ToArray());
			};
			Action funcDelete = () => {
				_affrows += dbContextBetch("DbContextBetchRemove");
				states.Clear();
			};
			Action funcInsert = () => {
				_affrows += dbContextBetch("DbContextBetchAdd");
				states.Clear();
			};
			Action<bool> funcUpdate = isLiveUpdate => {
				var affrows = 0;
				if (isLiveUpdate) affrows = dbContextBetch("DbContextBetchUpdateNow");
				else affrows = dbContextBetch("DbContextBetchUpdate");
				if (affrows == -999) { //最后一个元素已被删除
					states.RemoveAt(states.Count - 1);
					return;
				}
				if (affrows == -998 || affrows == -997) { //没有执行更新
					var laststate = states[states.Count - 1];
					states.Clear();
					if (affrows == -997) states.Add(laststate); //保留最后一个
				}
				if (affrows > 0) {
					_affrows += affrows;
					var islastNotUpdated = states.Count != affrows;
					var laststate = states[states.Count - 1];
					states.Clear();
					if (islastNotUpdated) states.Add(laststate); //保留最后一个
				}
			};

			while (_actions.Any() || states.Any()) {
				var info = _actions.Any() ? _actions.Dequeue() : null;
				if (oldinfo == null) oldinfo = info;
				var isLiveUpdate = false;

				if (_actions.Any() == false && states.Any() ||
					info != null && oldinfo.actionType != info.actionType ||
					info != null && oldinfo.stateType != info.stateType) {

					if (info != null && oldinfo.actionType == info.actionType && oldinfo.stateType == info.stateType) {
						//最后一个,合起来发送
						states.Add(info.state);
						info = null;
					}

					switch (oldinfo.actionType) {
						case ExecCommandInfoType.Insert:
							funcInsert();
							break;
						case ExecCommandInfoType.Delete:
							funcDelete();
							break;
					}
					isLiveUpdate = true;
				}

				if (isLiveUpdate || oldinfo.actionType == ExecCommandInfoType.Update) {
					if (states.Any())
						funcUpdate(isLiveUpdate);
				}

				if (info != null) {
					states.Add(info.state);
					oldinfo = info;
				}
			}
			isExecCommanding = false;
		}

19 Source : DataFilter.cs
with MIT License
from 2881099

public void Dispose() {
				_ondis?.Invoke();
			}

19 Source : SourceStringBuilder.cs
with MIT License
from 31

public void BlockPrefix(string delimiter, Action writeInner)
		{
			_indentPrefix.Append(delimiter);
			writeInner();
			_indentPrefix.Remove(_indentPrefix.Length - delimiter.Length, delimiter.Length);
		}

19 Source : IHandModel.cs
with MIT License
from 39M

public virtual void FinishHand() {
      if (OnFinish != null) {
        OnFinish();
      }
      isTracked = false;
    }

19 Source : IHandModel.cs
with MIT License
from 39M

public virtual void BeginHand() {
      if (OnBegin != null) {
        OnBegin();
      }
      isTracked = true;
    }

19 Source : Utils.cs
with MIT License
from 39M

public static IEnumerator WaitAndAction(float time, Action action)
    {
        yield return new WaitForSeconds(time);
        action();
    }

19 Source : Machine.cs
with MIT License
from 3RD-Dimension

public void Connect()
        {
            if (Connected)
                throw new Exception("Can't Connect: Already Connected");

            switch (Properties.Settings.Default.ConnectionType)
            {
                case ConnectionType.Serial:
                    SerialPort port = new SerialPort(Properties.Settings.Default.SerialPortName, Properties.Settings.Default.SerialPortBaud);
                    port.DtrEnable = Properties.Settings.Default.SerialPortDTR;
                    port.Open();
                    Connection = port.BaseStream;
                    break;
                default:
                    throw new Exception("Invalid Connection Type");
            }

            if (Properties.Settings.Default.LogTraffic)
            {
                try
                {
                    Log = new StreamWriter(Constants.LogFile);
                }
                catch (Exception e)
                {
                    NonFatalException("could not open logfile: " + e.Message);
                }
            }

            Connected = true;

            ToSend.Clear();
            ToSendPriority.Clear();
            Sent.Clear();
            ToSendMacro.Clear();

            Mode = OperatingMode.Manual;

            if (PositionUpdateReceived != null)
                PositionUpdateReceived.Invoke();

            WorkerThread = new Thread(Work);
            WorkerThread.Priority = ThreadPriority.AboveNormal;
            WorkerThread.Start();
        }

19 Source : Machine.cs
with MIT License
from 3RD-Dimension

public void Disconnect()
        {
            if (Log != null)
                Log.Close();
            Log = null;

            Connected = false;

            WorkerThread.Join();

            try
            {
                Connection.Close();
            }
            catch { }

            Connection.Dispose();
            Connection = null;

            Mode = OperatingMode.Disconnected;

            MachinePosition = new Vector3();
            WorkOffset = new Vector3();
            FeedRateRealtime = 0;
            CurrentTLO = 0;

            if (PositionUpdateReceived != null)
                PositionUpdateReceived.Invoke();

            Status = "Disconnected";
            DistanceMode = ParseDistanceMode.Absolute;
            Unit = ParseUnit.Metric;
            Plane = ArcPlane.XY;
            BufferState = 0;

            FeedOverride = 100;
            RapidOverride = 100;
            SpindleOverride = 100;

            if (OverrideChanged != null)
                OverrideChanged.Invoke();

            PinStateLimitX = false;
            PinStateLimitY = false;
            PinStateLimitZ = false;
            PinStateProbe = false;

            if (PinStateChanged != null)
                PinStateChanged.Invoke();

            ToSend.Clear();
            ToSendPriority.Clear();
            Sent.Clear();
            ToSendMacro.Clear();
        }

19 Source : Machine.cs
with MIT License
from 3RD-Dimension

public void SoftReset()
        {
            if (!Connected)
            {
                RaiseEvent(Info, "Not Connected");
                return;
            }

            Mode = OperatingMode.Manual;

            ToSend.Clear();
            ToSendPriority.Clear();
            Sent.Clear();
            ToSendMacro.Clear();
            ToSendPriority.Enqueue((char)0x18);

            BufferState = 0;

            FeedOverride = 100;
            RapidOverride = 100;
            SpindleOverride = 100;

            if (OverrideChanged != null)
                OverrideChanged.Invoke();

            SendLine("$G");
            SendLine("$#");
        }

19 Source : ObjectExtension.cs
with MIT License
from 3F

public static T E<T>(this T obj, Action act) => E(obj, _=> act());

19 Source : EnterNumberWindow.xaml.cs
with MIT License
from 3RD-Dimension

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			if (!Ok && User_Cancel != null)
				User_Cancel.Invoke();
		}

19 Source : Machine.cs
with MIT License
from 3RD-Dimension

private void ParseStatus(string line)
        {
            MatchCollection statusMatch = StatusEx.Matches(line);

            if (statusMatch.Count == 0)
            {
                NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line));
                return;
            }

            bool posUpdate = false;
            bool overrideUpdate = false;
            bool pinStateUpdate = false;
            bool resetPins = true;

            foreach (Match m in statusMatch)
            {
                if (m.Index == 1)
                {
                    Status = m.Groups[1].Value;
                    continue;
                }

                if (m.Groups[1].Value == "Ov")
                {
                    try
                    {
                        string[] parts = m.Groups[2].Value.Split(',');
                        FeedOverride = int.Parse(parts[0]);
                        RapidOverride = int.Parse(parts[1]);
                        SpindleOverride = int.Parse(parts[2]);
                        overrideUpdate = true;
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }

                else if (m.Groups[1].Value == "WCO")
                {
                    try
                    {
                        string OffsetString = m.Groups[2].Value;

                        if (Properties.Settings.Default.IgnoreAdditionalAxes)
                        {
                            string[] parts = OffsetString.Split(',');
                            if (parts.Length > 3)
                            {
                                Array.Resize(ref parts, 3);
                                OffsetString = string.Join(",", parts);
                            }
                        }

                        WorkOffset = Vector3.Parse(OffsetString);
                        posUpdate = true;
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }

                else if (SyncBuffer && m.Groups[1].Value == "Bf")
                {
                    try
                    {
                        int availableBytes = int.Parse(m.Groups[2].Value.Split(',')[1]);
                        int used = Properties.Settings.Default.ControllerBufferSize - availableBytes;

                        if (used < 0)
                            used = 0;

                        BufferState = used;
                        RaiseEvent(Info, $"Buffer State Synced ({availableBytes} bytes free)");
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }

                else if (m.Groups[1].Value == "Pn")
                {
                    resetPins = false;

                    string states = m.Groups[2].Value;

                    bool stateX = states.Contains("X");
                    if (stateX != PinStateLimitX)
                        pinStateUpdate = true;
                    PinStateLimitX = stateX;

                    bool stateY = states.Contains("Y");
                    if (stateY != PinStateLimitY)
                        pinStateUpdate = true;
                    PinStateLimitY = stateY;

                    bool stateZ = states.Contains("Z");
                    if (stateZ != PinStateLimitZ)
                        pinStateUpdate = true;
                    PinStateLimitZ = stateZ;

                    bool stateP = states.Contains("P");
                    if (stateP != PinStateProbe)
                        pinStateUpdate = true;
                    PinStateProbe = stateP;
                }

                else if (m.Groups[1].Value == "F")
                {
                    try
                    {
                        FeedRateRealtime = double.Parse(m.Groups[2].Value, Constants.DecimalParseFormat);
                        posUpdate = true;
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }

                else if (m.Groups[1].Value == "FS")
                {
                    try
                    {
                        string[] parts = m.Groups[2].Value.Split(',');
                        FeedRateRealtime = double.Parse(parts[0], Constants.DecimalParseFormat);
                        SpindleSpeedRealtime = double.Parse(parts[1], Constants.DecimalParseFormat);
                        posUpdate = true;
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }
            }

            SyncBuffer = false; //only run this immediately after button press

            //run this later to catch work offset changes before parsing position
            Vector3 NewMachinePosition = MachinePosition;

            foreach (Match m in statusMatch)
            {
                if (m.Groups[1].Value == "MPos" || m.Groups[1].Value == "WPos")
                {
                    try
                    {
                        string PositionString = m.Groups[2].Value;

                        if (Properties.Settings.Default.IgnoreAdditionalAxes)
                        {
                            string[] parts = PositionString.Split(',');
                            if (parts.Length > 3)
                            {
                                Array.Resize(ref parts, 3);
                                PositionString = string.Join(",", parts);
                            }
                        }

                        NewMachinePosition = Vector3.Parse(PositionString);

                        if (m.Groups[1].Value == "WPos")
                            NewMachinePosition += WorkOffset;

                        if (NewMachinePosition != MachinePosition)
                        {
                            posUpdate = true;
                            MachinePosition = NewMachinePosition;
                        }
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }

            }

            if (posUpdate && Connected && PositionUpdateReceived != null)
                PositionUpdateReceived.Invoke();

            if (overrideUpdate && Connected && OverrideChanged != null)
                OverrideChanged.Invoke();

            if (resetPins)  //no pin state received in status -> all zero
            {
                pinStateUpdate = PinStateLimitX | PinStateLimitY | PinStateLimitZ | PinStateProbe;  //was any pin set before

                PinStateLimitX = false;
                PinStateLimitY = false;
                PinStateLimitZ = false;
                PinStateProbe = false;
            }

            if (pinStateUpdate && Connected && PinStateChanged != null)
                PinStateChanged.Invoke();

            if (Connected && StatusReceived != null)
                StatusReceived.Invoke(line);
        }

19 Source : GameEventData.cs
with MIT License
from 404Lcc

public void Excute()
        {
            Callback?.Invoke();
        }

19 Source : ETTask.cs
with MIT License
from 404Lcc

[DebuggerHidden]
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void SetException(Exception exception)
        {
            if (_awaiterStatus != AwaiterStatus.Pending)
            {
                throw new InvalidOperationException("任务已完成");
            }
            _awaiterStatus = AwaiterStatus.Faulted;
            Action callback = (Action)_callback;
            callback?.Invoke();
            _callback = ExceptionDispatchInfo.Capture(exception);
        }

19 Source : ETTask.cs
with MIT License
from 404Lcc

[DebuggerHidden]
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void SetResult()
        {
            if (_awaiterStatus != AwaiterStatus.Pending)
            {
                throw new InvalidOperationException("任务已完成");
            }
            _awaiterStatus = AwaiterStatus.Succeeded;
            Action callback = (Action)_callback;
            callback?.Invoke();
            _callback = null;
        }

19 Source : ETTask.cs
with MIT License
from 404Lcc

[DebuggerHidden]
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void OnCompleted(Action continuation)
        {
            if (_awaiterStatus != AwaiterStatus.Pending)
            {
                continuation?.Invoke();
            }
            else
            {
                _callback = continuation;
            }
        }

19 Source : ETTask.cs
with MIT License
from 404Lcc

[DebuggerHidden]
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void UnsafeOnCompleted(Action continuation)
        {
            if (_awaiterStatus != AwaiterStatus.Pending)
            {
                continuation?.Invoke();
            }
            else
            {
                _callback = continuation;
            }
        }

See More Examples