//----------------------------------------------------------------------------
        // Construction
        //----------------------------------------------------------------------------

        public TrayApplicationContext()
        {
            this.disposed = false;
            InitializeComponent();
            this.statusText                     = null;
            this.bugBotMessageQueue             = new SharedMemTaggedBlobQueue(false, TaggedBlob.BugBotMessageQueueUniquifier);
            this.bugBotCommandQueue             = new SharedMemTaggedBlobQueue(false, TaggedBlob.BugBotCommandQueueUniquifier);
            this.shutdownMonitor                = new ShutdownMonitor(Program.TrayUniquifier);
            this.shutdownMonitor.ShutdownEvent += (sender, e) => ShutdownApp();

            this.threadStarter = new HandshakeThreadStarter("Swerve Tray Notification Thread", this.NotificationThreadLoop);

            Application.ApplicationExit += (object sender, EventArgs e) => RemoveIcon();
            this.trayIcon.Visible        = true;

            this.shutdownMonitor.StartMonitoring();
            StartBotBugNotificationThread();

            // Tell the service that we started
            try {
                this.bugBotCommandQueue.InitializeIfNecessary();
                this.bugBotCommandQueue.Write(new TaggedBlob(TaggedBlob.TagSwerveToolsTrayStarted, new byte[0]), 100);
            }
            catch (Exception)
            {
                // ignore
            }
        }
Example #2
0
 protected virtual void Dispose(bool notFromFinalizer)
 {
     if (!disposed)
     {
         this.disposed = true;
         if (notFromFinalizer)
         {
             this.bugbotMessageQueue?.Write(TaggedBlob.TagBugBotMessage, Resources.StoppingMessage);
         }
         this.bugbotMessageQueue?.Dispose();     this.bugbotMessageQueue  = null;
         this.bugBotCommandQueue?.Dispose();     this.bugBotCommandQueue  = null;
         this.commandQueueStarter?.Dispose();    this.commandQueueStarter = null;
         this.ReleaseDeviceNotificationHandles();
     }
 }
 protected override void Dispose(bool notFinalizer)
 {
     if (!disposed)
     {
         this.disposed = true;
         if (notFinalizer)
         {
             // Called from user's code. Can / should cleanup managed objects
             StopBotBugNotificationThread();
             this.shutdownMonitor?.StopMonitoring();
         }
         // Called from finalizers (and user code). Avoid referencing other objects.
         this.trayIcon?.Dispose();           this.trayIcon           = null;
         this.bugBotMessageQueue?.Dispose(); this.bugBotMessageQueue = null;
         this.bugBotCommandQueue?.Dispose(); this.bugBotCommandQueue = null;
         this.threadStarter?.Dispose();      this.threadStarter      = null;
     }
     base.Dispose(notFinalizer);
 }
Example #4
0
        //-----------------------------------------------------------------------------------------
        // Construction
        //-----------------------------------------------------------------------------------------

        public USBMonitor(IDeviceEvents eventRaiser, ITracer tracer, IntPtr notificationHandle, bool notificationHandleIsService)
        {
            this.eventRaiser                 = eventRaiser;
            this.tracer                      = tracer;
            this.notificationHandle          = notificationHandle;
            this.notificationHandleIsService = notificationHandleIsService;

            this.bugbotMessageQueue = new SharedMemTaggedBlobQueue(true, TaggedBlob.BugBotMessageQueueUniquifier);
            this.bugbotMessageQueue.InitializeIfNecessary();
            this.bugBotCommandQueue = new SharedMemTaggedBlobQueue(true, TaggedBlob.BugBotCommandQueueUniquifier);
            this.bugBotCommandQueue.InitializeIfNecessary();

            this.commandQueueStarter = new HandshakeThreadStarter("Command Q Listener", CommandQueueListenerThread);

            this.androidDeviceDatabase = new AndroidDeviceDatabase();

            UpdateStatusNoRememberedConnections();
            this.bugbotMessageQueue.Write(TaggedBlob.TagBugBotMessage, Resources.StartingMessage);

            this.deviceInterfacesOfInterest = new List <Guid>();
            this.deviceNotificationHandles  = new List <IntPtr>();

            this.started = false;
        }