Exemplo n.º 1
0
        /// <summary>
        /// Function executed when a slave accepts the master
        /// </summary>
        private static void MasterAcceptFunction(NetworkStream _stream)
        {
            Message       m;
            NetworkStream stream = _stream;

            try
            {
                while (stream.CanRead && Form1.getForm().isConnectedMaster)
                {
                    try
                    {
                        m = Message.ReadFromSocket(stream);

                        if (m.typeMessage == Message.TypeMessage.Input)
                        {
                            SlaveGlobalVars.SocketToDispatcherQueue.Enqueue(m.Content <INPUT_EXTENDED>());

                            //formUI.BeginInvoke((Action)(() => { ((Form1)formUI).setLabel("get_000"); InputDispatcher.DispatchInput(); ((Form1)formUI).setLabel("get " + m.Content<INPUT>().mkhi.ki.Vk); }));
                            formUI.BeginInvoke((Action)(() => { /*((Form1)formUI).setLabel("get_000"); */ InputDispatcher.DispatchInput(); /* ((Form1)formUI).setLabel("get " + m.Content<INPUT>().mkhi.ki.Vk); */ }));

                            //throw new Exception("ok");


                            //SlaveGlobalVars.SocketToDispatcherQueue.Add(m.Content<INPUT>());
                        }
                        else if (m.typeMessage == Message.TypeMessage.ClipboardAttached)
                        {//TODO move to another socket
                            formUI.BeginInvoke((Action)(() => { ((Form1)formUI).setLabel("clipboard copying"); CommonClasses.ManageClipboard.setCurrentClipboard(m); ((Form1)formUI).setLabel("clipboard copied"); }));
                        }
                        else if (m.typeMessage == Message.TypeMessage.Error)
                        {
                            SlaveGlobalVars.isTarget = false;
                            return;
                        }
                        else if (m.typeMessage == Message.TypeMessage.CloseConnection)
                        {
                            Form1.getForm().isConnectedMaster = false;
                            return;//in some case is not reached
                        }
                        else
                        {
                            System.Threading.Thread.Sleep(10);//TODO use async
                        }
                    }
                    catch (Exception e)
                    {
                        int a;
                        //no problem?
                    }
                }
            }
            catch (Exception e)
            {
                Form1.getForm().isConnectedMaster = false;
                //Console.WriteLine("Can't read from socket anymore");
            }
        }
Exemplo n.º 2
0
 public static void BeginInvoke(Action action)
 {
     if (CurrentDispatcher != null)
     {
         CurrentDispatcher.BeginInvoke(action);
     }
     else if (MainForm != null)
     {
         MainForm.BeginInvoke(action);
     }
     else
     {
         action();
     }
 }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
 public void DataLoadedHandler(object sender, ScrapeResponseEventArgs e)
 {
     if (_guiDispatcher != null)
     {
         Action action = () => updateOnDataLoaded(e.response);
         _guiDispatcher.BeginInvoke(action);
     }
 }
Exemplo n.º 5
0
 public static void OpenMessage(this System.Windows.Forms.Form form, Frm.MessageType type, string txt)
 {
     if (form != null)
     {
         form.BeginInvoke(new Action(() =>
         {
             Frm.Message message = new Frm.Message(form, type, txt);
             message.Show(form);
         }));
     }
 }
Exemplo n.º 6
0
Arquivo: test.cs Projeto: mloc/scc
 static void ShowMessageInForm(System.Windows.Forms.Form owner_form, string msg)
 {
     if (owner_form != null)
     {
         owner_form.BeginInvoke(new Action(() =>
                                           System.Windows.Forms.MessageBox.Show(owner_form, msg)
                                           ));
     }
     else
     {
         System.Windows.Forms.MessageBox.Show(msg);
     }
 }
Exemplo n.º 7
0
Arquivo: test.cs Projeto: mloc/scc
        static void ShowMessageInForm(System.Windows.Forms.Form owner_form, string caption, string fmt, params object[] args)
        {
            string msg = string.Format(fmt, args);

            if (owner_form != null)
            {
                owner_form.BeginInvoke(new Action(() =>
                                                  System.Windows.Forms.MessageBox.Show(owner_form, msg, caption)
                                                  ));
            }
            else
            {
                System.Windows.Forms.MessageBox.Show(msg, caption);
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Bring the view forward.
 /// </summary>
 private void _activateView(CadKit.Interfaces.IDocumentView view)
 {
     System.Windows.Forms.Form form = view as System.Windows.Forms.Form;
     if (null != form)
     {
         if (true == form.InvokeRequired)
         {
             form.BeginInvoke(new VoidReturnZeroArgumentsDelegate(form.Activate));
         }
         else
         {
             form.Activate();
         }
     }
 }
Exemplo n.º 9
0
 public static WebRTCCommons.CustomAwaiter <bool> ContextSwitchToMessagePumpAsync(this System.Windows.Forms.Form f)
 {
     WebRTCCommons.CustomAwaiter <bool> retVal = new WebRTCCommons.CustomAwaiter <bool>();
     retVal.forceWait();
     try
     {
         f.BeginInvoke((Action <WebRTCCommons.CustomAwaiter <bool> >)((a) =>
         {
             a.SetComplete(true);
         }), retVal);
     }
     catch
     {
     }
     return(retVal);
 }
Exemplo n.º 10
0
 private static void DisposeCWB(csExWB.cEXWB c)
 {
     if (m_form.InvokeRequired)
     {
         log.Debug("Dispose CWB...");
         m_form.BeginInvoke(new DisposeCWBDelegator(DisposeCWB), new object[] { c });
     }
     else
     {
         try
         {
             c.Dispose();
         }
         catch (Exception e)
         {
             log.Error(e);
         }
     }
 }
Exemplo n.º 11
0
 /// <summary>
 /// Zobraz danou zprávu a ikonku
 /// </summary>
 /// <param name="message"></param>
 /// <param name="icon"></param>
 private static void _ShowMsg(string message, System.Windows.Forms.MessageBoxIcon icon)
 {
     System.Windows.Forms.Form mainForm = MainForm;
     if (mainForm == null)
     {
         _ShowMsgGui(null, message, icon);
     }
     else if (mainForm.IsDisposed)
     {
         _ShowMsgGui(null, message, icon);
     }
     else if (mainForm.InvokeRequired)
     {
         mainForm.BeginInvoke(new Action <System.Windows.Forms.Form, string, System.Windows.Forms.MessageBoxIcon>(_ShowMsgGui), mainForm, message, icon);
     }
     else
     {
         _ShowMsgGui(mainForm, message, icon);
     }
 }
Exemplo n.º 12
0
 /// <summary>
 /// Close the form.
 /// </summary>
 protected void _closeForm()
 {
     try
     {
         System.Windows.Forms.Form form = this.Form;
         if (null != form)
         {
             if (true == form.InvokeRequired)
             {
                 form.BeginInvoke(new CloseFormDelegate(this._closeForm));
             }
             else
             {
                 form.Close();
             }
         }
     }
     catch (System.Exception e)
     {
         System.Console.WriteLine("Error 2179235090: {0}", e.Message);
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// 异步发生异常触发事件
        /// </summary>
        /// <param name="e">异常信息</param>
        private void ExceptionEventFire(Exception e)
        {
            if (AsyncException != null)
            {
                if (AsyncException.Target is System.Windows.Forms.Form)
                {
                    System.Windows.Forms.Form f = AsyncException.Target as System.Windows.Forms.Form;
                    f.BeginInvoke(AsyncException, e);
                }

                if (AsyncException.Target is System.Windows.Forms.Control)
                {
                    System.Windows.Forms.Control c = AsyncException.Target as System.Windows.Forms.Control;
                    c.BeginInvoke(AsyncException, e);
                }
                else
                {
                    //当前无订阅异步出错的事件处理
                    throw new Exception("异步出错事件为空!");
                }
            }
            SetVarAtAsyncFinished();
        }