Esempio n. 1
0
 private void SafeClear()
 {
     if (txtInput.InvokeRequired)
     {
         var d = new NoParamDelegate(SafeClear);
         txtInput.Invoke(d, new object[] { });
     }
     else
     {
         console.ClearOutput();
     }
 }
Esempio n. 2
0
 private void SafeStyleEditor()
 {
     if (console.InvokeRequired)
     {
         var d = new NoParamDelegate(SafeStyleEditor);
         console.Invoke(d, new object[] { });
     }
     else
     {
         editor_StyleNeeded(null, null);
     }
 }
Esempio n. 3
0
 private void SafeShowInput()
 {
     if (txtInput.InvokeRequired)
     {
         var d = new NoParamDelegate(SafeShowInput);
         txtInput.Invoke(d, new object[] { });
     }
     else
     {
         txtInput.Show();
         txtInput.Focus();
     }
 }
Esempio n. 4
0
        public new void Close()
        {
            // may be called from a destructor which may be executed
            // in another thread...
            if (InvokeRequired)
            {
                NoParamDelegate del = new NoParamDelegate(Close);
                Invoke(del);
                return;
            }

            Hide();
            base.Close();
        }
Esempio n. 5
0
 internal void SetDelegates(NoParamDelegate go, FindFirstCharDelegate firstChar, NoParamDelegate trackCount)
 {
     goMethod             = go;
     findFirstCharMethod  = firstChar;
     initTrackCountMethod = trackCount;
 }
    private Semaphore threadMutex = new Semaphore(1, 1); //Ensure that  only one operation is started at the same time
    //private event NoParamDelegate ThreadNotStarted; // This event is signaled if a background thread couldn't be started because another one is runniung
	private void SpawnThread(NoParamDelegate action, bool showPendingError = true, int wait = 500)
	{
        Thread t = new Thread(
            new ThreadStart(
                delegate()
                {
                    if (threadMutex.WaitOne(wait))
                    {
                        try
                        {	
							Gtk.Application.Invoke (delegate {
              					replyStatusbar.Pop(1);
								ShowConnectIcon();
							});
							action();
                        }
						catch (MonoBrickException e){
							Gtk.Application.Invoke (delegate {
              					if(e is MonoBrickException)
									ShowWarningIcon();	
								else
									ShowErrorIcon();
								replyStatusbar.Pop(1);
								replyStatusbar.Push(1,e.Message);
						 	});
							if(e is ConnectionException)
								brick.Connection.Close();
						}
						catch(Exception e){
							Gtk.Application.Invoke (delegate {
              					MessageDialog md = new MessageDialog (this, DialogFlags.Modal, MessageType.Error, ButtonsType.Close, "\n" + e.Message);
            					md.Icon = global::Gdk.Pixbuf.LoadFromResource (MessageDialogIconName);
								md.Run ();
								md.WindowPosition = Gtk.WindowPosition.CenterOnParent;
            					md.Destroy();
       					 	});
						
						}
                        finally
                        {
                            threadMutex.Release();
                        }
                    }
                    else
                    {
                        if(showPendingError){
							Gtk.Application.Invoke (delegate {
	              					MessageDialog md = new MessageDialog (this, DialogFlags.Modal, MessageType.Error, ButtonsType.Close, "\nUnable to send command to NXT.\nAnother command is pending");
	            					md.Icon = global::Gdk.Pixbuf.LoadFromResource (MessageDialogIconName);
									md.WindowPosition = Gtk.WindowPosition.CenterOnParent;
									md.Run ();
	            					md.Destroy();
	       					});
						}
                    }
                }
                ));
        t.IsBackground = true;
		t.Priority = ThreadPriority.AboveNormal;
        t.Start();
    }
 internal void SetDelegates(NoParamDelegate go, FindFirstCharDelegate firstChar, NoParamDelegate trackCount) {
     goMethod = go;
     findFirstCharMethod = firstChar;
     initTrackCountMethod = trackCount;
 }
    private Semaphore threadMutex = new Semaphore(1, 1); //Ensure that  only one operation is started at the same time
    //private event NoParamDelegate ThreadNotStarted; // This event is signaled if a background thread couldn't be started because another one is runniung
    private void SpawnThread(NoParamDelegate action, bool showPendingError = true, int wait = 500)
    {
        Thread t = new Thread(
            new ThreadStart(
                delegate()
        {
            if (threadMutex.WaitOne(wait))
            {
                try
                {
                    Gtk.Application.Invoke(delegate {
                        replyStatusbar.Pop(1);
                        ShowConnectIcon();
                    });
                    action();
                }
                catch (MonoBrickException e) {
                    Gtk.Application.Invoke(delegate {
                        if (e is MonoBrickException)
                        {
                            ShowWarningIcon();
                        }
                        else
                        {
                            ShowErrorIcon();
                        }
                        replyStatusbar.Pop(1);
                        replyStatusbar.Push(1, e.Message);
                    });
                    if (e is ConnectionException)
                    {
                        brick.Connection.Close();
                    }
                }
                catch (Exception e) {
                    Gtk.Application.Invoke(delegate {
                        MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Close, "\n" + e.Message);
                        md.Icon          = global::Gdk.Pixbuf.LoadFromResource(MessageDialogIconName);
                        md.Run();
                        md.WindowPosition = Gtk.WindowPosition.CenterOnParent;
                        md.Destroy();
                    });
                }
                finally
                {
                    threadMutex.Release();
                }
            }
            else
            {
                if (showPendingError)
                {
                    Gtk.Application.Invoke(delegate {
                        MessageDialog md  = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Close, "\nUnable to send command to NXT.\nAnother command is pending");
                        md.Icon           = global::Gdk.Pixbuf.LoadFromResource(MessageDialogIconName);
                        md.WindowPosition = Gtk.WindowPosition.CenterOnParent;
                        md.Run();
                        md.Destroy();
                    });
                }
            }
        }
                ));

        t.IsBackground = true;
        t.Priority     = ThreadPriority.AboveNormal;
        t.Start();
    }