Beispiel #1
0
        void proc_Exited(object sender, EventArgs e)
        {
            Process proc = (Process)sender;


            int iExitCode = proc.ExitCode;


            bool blFileExists = File.Exists(tempEncodedVideo.EncodedVideoPath);


            tempEncodedVideo.Success = (iExitCode.Equals(0) && blFileExists);


            EncodeFinishedEventArgs efe = new EncodeFinishedEventArgs();

            efe.EncodedVideoInfo = tempEncodedVideo;


            if (tempCaller != null)
            {
                tempCaller.BeginInvoke(new EncodeFinishedEventHandler(OnEncodeFinished), tempCaller, efe);
            }
            else
            {
                DoEncodeFinished(efe);
            }

            iProgressErrorCount = 0;


            proc.Close();
        }
 public IAsyncResult BeginProgressDlg(String msg)
 {
     if (!IsValid())
     {
         return(null);
     }
     return(_parentControl.BeginInvoke(delProgressDlg, ProgressStatusType.BackgroundWorkStart, msg));
 }
Beispiel #3
0
 private void ConnectionClosed(Exception e)
 {
     SyncControl.BeginInvoke((System.Action) delegate
     {
         if (addon != null)
         {
             GMEConsole console = GMEConsole.CreateFromProject(addon.Project);
             console.Error.WriteLine("Connection to MetaLink lost.");
             //componentEditMessages.Clear();
             interests.Clear();
             AssemblyID = null;
             CloseMetaLinkBridge();
             if (console.gme != null)
             {
                 // Marshal.FinalReleaseComObject(console.gme); is this needed?
             }
             Enable(false);
             if (syncedComponents.Count > 0)
             {
                 bool inTx = ((addon.Project.ProjectStatus & 8) != 0);
                 if (inTx == false)
                 {
                     addon.Project.BeginTransactionInNewTerr();
                 }
                 try
                 {
                     foreach (string id in syncedComponents.Keys)
                     {
                         ISIS.GME.Common.Interfaces.Base model = CyphyMetaLinkUtils.GetComponentAssemblyByGuid(addon.Project, id);
                         if (model == null)
                         {
                             model = CyphyMetaLinkUtils.GetComponentByAvmId(addon.Project, id);
                         }
                         if (model != null)
                         {
                             HighlightInTree(model, 0);
                         }
                     }
                 }
                 finally
                 {
                     if (inTx == false)
                     {
                         addon.Project.AbortTransaction();
                     }
                 }
                 syncedComponents.Clear();
                 designIdToCadAssemblyXml.Clear();
             }
         }
     });
 }
Beispiel #4
0
 public override void Post(EventHandler target, object sender, EventArgs args)
 {
     if (target != null)
     {
         if (fUI.InvokeRequired)
         {
             fUI.BeginInvoke(target, sender, args);
         }
         else
         {
             target(sender, args);
         }
     }
 }
Beispiel #5
0
 void RiseMachineStatusChanged()
 {
     if (MachineStatusChanged != null)
     {
         if (syncro.InvokeRequired)
         {
             syncro.BeginInvoke(new dlgOnMachineStatus(RiseMachineStatusChanged));
         }
         else
         {
             MachineStatusChanged();
         }
     }
 }
Beispiel #6
0
        /// <summary>
        /// 异步方法结束触发事件
        /// </summary>
        /// <param name="ret">异步方法返回的值</param>
        private void FinishedEventFire(object ret)
        {
            if (AsyncFinished != null)
            {
                if (AsyncFinished.Target is System.Windows.Forms.Form)
                {
                    System.Windows.Forms.Form f = AsyncFinished.Target as System.Windows.Forms.Form;
                    f.BeginInvoke(AsyncFinished, ret);
                }
                else if (AsyncFinished.Target is System.Windows.Forms.Control)
                {
                    System.Windows.Forms.Control c = AsyncFinished.Target as System.Windows.Forms.Control;
                    if (!c.IsDisposed)
                    {
                        c.BeginInvoke(AsyncFinished, ret);
                    }
                    //c.BeginInvoke(AsyncFinished, ret);
                }
                else
                {
                    AsyncFinished(ret);
                }
            }
            else
            {
                //当前无订阅异步出错的事件处理
                throw new Exception("异步完成事件为空!");
            }

            SetVarAtAsyncFinished();
        }
Beispiel #7
0
        /// <summary>
        /// Method call event event safety - for using event beyond threads
        /// </summary>
        /// <param name="method">event delegate</param>
        /// <param name="args">event arguments - the first one is the calling method like "this"</param>
        public static void Invoke(Delegate method, object[] args)
        {
            if (method != null)
            {
                foreach (Delegate handler in method.GetInvocationList())
                {
                    if (handler.Target is System.Windows.Forms.Control)
                    {
                        System.Windows.Forms.Control target = handler.Target as System.Windows.Forms.Control;

                        if (target.IsHandleCreated)
                        {
                            target.BeginInvoke(handler, args);
                        }
                    }
                    else if (handler.Target is System.ComponentModel.ISynchronizeInvoke)
                    {
                        System.ComponentModel.ISynchronizeInvoke target = handler.Target as System.ComponentModel.ISynchronizeInvoke;
                        target.BeginInvoke(handler, args);
                    }
                    else
                    {
                        handler.DynamicInvoke(args);
                    }
                }
            }
        }
Beispiel #8
0
        private void UpdateSolutionThread()
        {
            bool   success      = false;
            string errorMessage = string.Empty;

            try
            {
                UpdateSolution();
                success = true;
            }
            catch (Exception e)
            {
                errorMessage = "An error occured while attempting to update the solution: " + e.ToString();
            }
            finally
            {
                // Fire the processing complete event
                if (OnSolutionProcessingComplete != null)
                {
                    if (OnSolutionProcessingComplete.Target is System.Windows.Forms.Control)
                    {
                        System.Windows.Forms.Control target = OnSolutionProcessingComplete.Target as System.Windows.Forms.Control;
                        target.BeginInvoke(OnSolutionProcessingComplete, new Object[] { success, errorMessage });
                    }
                    else
                    {
                        OnSolutionProcessingComplete(success, errorMessage);
                    }
                }
            }
        }
Beispiel #9
0
        private void CaptureLoop(DXGIManager manager, System.Windows.Forms.Control controlToDraw)
        {
            _dataStream = new DataStream(_clipRect.Width * _clipRect.Height * 4, true, true);

            while (true)
            {
                int signalId = EventWaitHandle.WaitAny(_waitSignals, Timeout.Infinite);

                if (signalId == 0)
                {
                    break;
                }

                if (manager.Capture(copyFrameBuffer, 1000) == true)
                {
                    SharpDX.Direct2D1.Bitmap bitmap = _renderTarget.CreateBitmap(_dataStream);
                    if (bitmap != null)
                    {
                        _queue.Add(bitmap);
                    }
                }

                if (controlToDraw.Created)
                {
                    controlToDraw.BeginInvoke((Action)(() => this.DrawToWindow()));
                }
            }
        }
Beispiel #10
0
 /// <summary>
 /// 在创建控件的基础句柄所在线程上,用指定的参数异步执行指定委托。
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="ctl"></param>
 /// <param name="doit"></param>
 /// <param name="aras"></param>
 public static void QueueInvoke <T>(this System.Windows.Forms.Control ctl, Action <T> doit, T aras)
 {
     if (ctl == null)
     {
         throw new ArgumentNullException("ctl");
     }
     ctl.BeginInvoke(doit, aras);
 }
Beispiel #11
0
        /// <summary>
        ///   Execute on UI thread asynchronously (don't wait for completion)
        /// </summary>
        /// <param name="control">Parent object</param>
        /// <param name="code">Code to execute</param>
        /// <example>
        ///   Store.ExecuteThread(this, () =>
        ///   {
        ///     Text1.Text = "Something new";
        ///   });
        /// </example>
        public static void ExecuteThread(this System.Windows.Forms.Control control, Action code)
        {
            if (control.InvokeRequired)
            {
                control.BeginInvoke(code);
                return;
            }

            code.Invoke();
        }
Beispiel #12
0
 protected override void next_a_round()
 {
     try
     {
         _ctrl.BeginInvoke(_runTask);
     }
     catch (System.InvalidOperationException ec)
     {
         Trace.Fail(ec.Message, ec.StackTrace);
     }
 }
Beispiel #13
0
 /// <summary>
 /// Executes the Action asynchronously on the UI thread, does not block execution on the calling thread.
 /// </summary>
 /// <param name="control"></param>
 /// <param name="code"></param>
 public static void UIThread(this System.Windows.Forms.Control @this, Action code)
 {
     if (@this.InvokeRequired)
     {
         @this.BeginInvoke(code);
     }
     else
     {
         code.Invoke();
     }
 }
 public static void UpdateUI(this System.Windows.Forms.Control control, Action updateAction)
 {
     if (control.InvokeRequired)
     {
         control.BeginInvoke(updateAction);
     }
     else
     {
         control.Invoke(updateAction);
     }
 }
Beispiel #15
0
 public static void UpdateControl(System.Windows.Forms.Control cntrl, Action myAction)
 {
     if (!cntrl.InvokeRequired)
     {
         myAction();
     }
     else
     {
         cntrl.BeginInvoke(myAction);
     }
 }
Beispiel #16
0
        public static bool TryBeginInvoke(this System.Windows.Forms.Control control, Action action)
        {
            if (!control.InvokeRequired)
            {
                return(false);
            }

            control.BeginInvoke(action);

            return(true);
        }
Beispiel #17
0
 internal void Post(SendOrPostCallback cb, object args)
 {
     if (m_synchronizeInvoke != null)
     {
         m_synchronizeInvoke.BeginInvoke(cb, args);
     }
     else
     {
         ThreadPool.QueueUserWorkItem(cb, args);
     }
 }
    void PollNow(object sender, EventArgs e)
    {
        var temp = Polled;

        if ((temp != null) && (null != consumerContext))
        {
            consumerContext.BeginInvoke(new Action(() =>
            {
                Polled(this, new EventArgs());
            }));
        }
    }
Beispiel #19
0
 //private delegate void InvokeDelegate();
 public override void OnInvoke(MethodInterceptionArgs args)
 {
     System.Windows.Forms.Control main = (System.Windows.Forms.Control)args.Instance;
     if (main.InvokeRequired)
     {
         main.BeginInvoke(new Action(args.Proceed));
     }
     else
     {
         args.Proceed();
     }
 }
 public static LambdaVoid0Inp makeLambdaVoid0InpInvoke(LambdaVoid0Inp l, System.Windows.Forms.Control c)
 {
     return(delegate()
     {
         if (c.InvokeRequired)
         {
             c.BeginInvoke(l);
         }
         else
         {
             l();
         }
     });
 }
Beispiel #21
0
        /// <summary>
        /// Loads a script instance
        /// </summary>
        public void Run(object owner, List <string> scripts)
        {
#if DEBUG
            var isDebug = true;
#else
            var isDebug = false;
#endif
            Assembly oldScript;
            if (Scripts.TryGetValue(owner, out oldScript))
            {
                oldScript.UnloadOwnerDomain();
                Scripts.Remove(owner);
            }

            try
            {
                CSScript.EvaluatorConfig.Engine = EvaluatorEngine.Mono;
                CSScript.MonoEvaluator.CompilerSettings.Platform = Mono.CSharp.Platform.X64;
                List <string> references = new List <string>()
                {
                    "TensorFlow.NET.dll",
                    "Google.Protobuf.dll",
                    "Newtonsoft.Json",
                    "NumSharp.Lite",
                    "netstandard",
                    "System.Memory",
                    "System.Numerics"
                };
                foreach (var s in Scripts.Values)
                {
                    references.Add(s.Location);
                }
                Scripts[owner] = CSScript.LoadFiles(scripts.ToArray(), null, isDebug, references.ToArray());

                // Check if a "Run" method should be executed
                MethodDelegate runFunc = null;
                try { runFunc = Scripts[owner].GetStaticMethod("*.Run", this); } catch (Exception ex) { };
                if (runFunc != null)
                {
                    System.Threading.Tasks.Task.Run(() => { runFunc(this); });
                }
            }
            catch (Exception ex)
            {
                GuiContainer.BeginInvoke((Action)(() =>
                {
                    System.Windows.Forms.MessageBox.Show(ex.ToString());
                }));
            }
        }
 public static void SafeInvoke(this System.Windows.Forms.Control control, InvokeHandler handler)
 {
     if (control.InvokeRequired)
     {
         //control.Invoke(handler);
         control.BeginInvoke(handler);
         return;
     }
     else
     {
         handler();
         return;
     }
 }
Beispiel #23
0
        public bool Execute(System.Windows.Forms.Control context, Delegate function, params object[] parameters)
        {
            lock (this.lockObject)
            {
                if (context.InvokeRequired)
                {
                    int maxLoop = 100;

                    while (!context.IsHandleCreated)
                    {
                        System.Threading.Thread.Sleep(10);

                        if (--maxLoop <= 0)
                        {
                            // Failed to create control. Release thread.
                            return(false);
                        }
                    }

                    if (parameters == null)
                    {
                        context.BeginInvoke(function);
                    }
                    else
                    {
                        context.BeginInvoke(function, parameters);
                    }

                    // Return false here since further calls shall not be executed.
                    // A new async call had been invoked
                    return(false);
                }
            }

            return(true);
        }
Beispiel #24
0
        /// <summary>
        /// Handles process exit
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void proc_Exited(object sender, EventArgs e)
        {
            //Get process
            Process proc = (Process)sender;

            //Get the process exit code
            int iExitCode = proc.ExitCode;

            //Check if file exists
            bool blFileExists = File.Exists(tempEncodedVideo.EncodedVideoPath);

            //Set success
            tempEncodedVideo.Success = (iExitCode.Equals(0) && blFileExists);

            //Construct new finished event args
            EncodeFinishedEventArgs efe = new EncodeFinishedEventArgs();

            //Set the encode video finished event's VideoInfo object
            efe.EncodedVideoInfo = tempEncodedVideo;

            //Invoke/Fire real finished event
            if (tempCaller != null)
            {
                tempCaller.BeginInvoke(new EncodeFinishedEventHandler(OnEncodeFinished), tempCaller, efe);
            }
            else
            {
                DoEncodeFinished(efe);
            }

            //Reset progress error count
            iProgressErrorCount = 0;

            //Release resourced from process
            proc.Close();
        }
Beispiel #25
0
        public static System.IAsyncResult BeginInvokeMSS(
            System.Windows.Forms.Control target,
            System.Delegate method)
        {
            object result;

            if (TestSpecificStubsUtil.RunTestSpecificStub(System.Reflection.MethodBase.GetCurrentMethod(), new object[] { target, method }, out result))
            {
                return((System.IAsyncResult)result);
            }
            else
            {
                return(target.BeginInvoke(method));
            }
        }
Beispiel #26
0
 private void AddToStatus(string message)
 {
     if (OnSolutionProcessingStatus != null)
     {
         if (OnSolutionProcessingStatus.Target is System.Windows.Forms.Control)
         {
             System.Windows.Forms.Control target = OnSolutionProcessingStatus.Target as System.Windows.Forms.Control;
             target.BeginInvoke(OnSolutionProcessingStatus, new Object[] { message });
         }
         else
         {
             OnSolutionProcessingStatus(message);
         }
     }
     System.Threading.Thread.Sleep(100);
 }
 public static LambdaVoid1Inp <I> makeLambdaVoid1InpInvoke <I>(LambdaVoid1Inp <I> l, System.Windows.Forms.Control c)
 {
     return(delegate(I x)
     {
         if (c.InvokeRequired)
         {
             //Console.WriteLine("c == null:" + (c == null) + " d==null: " + (d == null) + " x == null: " + (x == null));
             c.BeginInvoke(l, x); //new I[] { x });
             //c.BeginInvoke(d, x); //new I[] { x });
         }
         else
         {
             l(x);
         }
     });
 }
Beispiel #28
0
        public static void InvokeAsync(System.Windows.Forms.Control dispatcherObject, Action action, AsyncInvokeMode mode = AsyncInvokeMode.AsyncOnly)
        {
            if (dispatcherObject == null || dispatcherObject.IsDisposed)
            {
                return;
            }

            if (mode == AsyncInvokeMode.AllowSyncInvoke && !dispatcherObject.InvokeRequired)
            {
                action.Invoke();
            }
            else
            {
                dispatcherObject.BeginInvoke(action);
            }
        }
Beispiel #29
0
        /// <summary>
        /// Schedules action to be executed on the message loop associated with the control.
        /// </summary>
        public IDisposable Schedule(Action action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            var cancelable = new BooleanDisposable();

            control.BeginInvoke(new Action(() =>
            {
                if (!cancelable.IsDisposed)
                {
                    action();
                }
            }));
            return(cancelable);
        }
Beispiel #30
0
 /// <summary>
 /// se encarga de lanzar el callback. Tiene en cuenta el tipo de destino
 /// </summary>
 /// <param name="Callback"></param>
 internal void ExecuteCallback(OverlayRequest request)
 {
     // liberamos el ManualResetEvent
     ((ManualResetEvent)request.Async.AsyncWaitHandle).Set();
     // llamamos al callback de SendRequest si existe
     if (request.Async.Callback != null)
     {
         if (request.Async.Callback.Target is System.Windows.Forms.Control)
         {
             System.Windows.Forms.Control targetControl =
                 (System.Windows.Forms.Control)request.Async.Callback.Target;
             IAsyncResult ar = targetControl.BeginInvoke(request.Async.Callback,
                                                         new object[] { request.Async });
         }
         else
         {
             request.Async.Callback(request.Async);
         }
     }
 }