Opening a new form then returning to the original

Supporting Visual Studio on Windows
Ironbark
Fresh meat
Posts: 1
Joined: Fri Aug 16, 2013 10:00 pm
Contact:

Opening a new form then returning to the original

Postby Ironbark » Mon Aug 19, 2013 5:47 am

I open and attach my bridge phidget on my main form, then hide it and open a second form. On this second form I only enter limits etc, then close it and show the main form again.

I have based the main form essentially on the example in the downloads with very little modification.

The phidget is gone and will not re-attach.

I would greatly appreciate any guidance on the trick to getting this working.

DenisFerrari
Phidgetsian
Posts: 12
Joined: Tue Mar 28, 2017 12:41 am
Contact:

Re: Opening a new form then returning to the original

Postby DenisFerrari » Tue Mar 28, 2017 1:31 am

Hi,
I just started to use Bridge and I've too started from VB2008 BridgeFull example.

I've noticed that as soon you have the Deactivate event of my current form, it's best to do Bridge.Close() and then reopen it one Activate event. Otherwise it does exactly like that, I mean, it stays disconnected and not working anymore.

Also, in my case, I've 3 forms all using the bridge.

While passing from one form to another, I do a Bridge.Close(), then Me.Close, then Newform.Show and it works.

Only problems I often have is that while loosing focus on the form, or reducing the form and getting back to it, my VB2008 app freezes and stops exaclty on current form Bridge.Close() row.

And I still do not understand why it doeas that.

Any help is highly appreciated.

User avatar
Patrick
Lead Developer
Posts: 3052
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Opening a new form then returning to the original

Postby Patrick » Tue Mar 28, 2017 8:35 am

You can close/open, but you may want to move your bridge code to another class and just share as a global singleton.

-Patrick

DenisFerrari
Phidgetsian
Posts: 12
Joined: Tue Mar 28, 2017 12:41 am
Contact:

Re: Opening a new form then returning to the original

Postby DenisFerrari » Tue Mar 28, 2017 8:52 am

Hi Patrick,
opening the Bridge only on start-up Form (that calls the others etc.) and pass to the rest was exactly my initial idal, but I still have not been able to do this.

Any help on this too ?

Thank you

User avatar
Patrick
Lead Developer
Posts: 3052
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Opening a new form then returning to the original

Postby Patrick » Tue Mar 28, 2017 11:40 am

Create a singleton class, which your forms will all share. The forms can register/deregister for events as they come up/down.

Since the PhidgetBridge object isn't owned by your forms, you will need to handle Invoke yourself if you need to access the form directly from and Phidget events.

For example:

Code: Select all

public class BridgeSingleton
{
   private static PhidgetBridge instance;

   private BridgeSingleton() {}

   public static PhidgetBridge Bridge
   {
      get
      {
         if (instance == null)
         {
            instance = new PhidgetBridge();
            instance.open();
            instance.waitForAttachement(500);
         }
         return instance;
      }
   }
}

Then, in your forms:

Code: Select all

BridgeSingleton.Bridge.BridgeData += BridgeDataEventHandler;


Note: this is pretty basic/untested. You would probably want to implement some sort of static connect function so you can handle waitForAttachement timeouts, or don't waitForAttachement, but handle attach/detach events, etc...

-Patrick

DenisFerrari
Phidgetsian
Posts: 12
Joined: Tue Mar 28, 2017 12:41 am
Contact:

Re: Opening a new form then returning to the original

Postby DenisFerrari » Tue Mar 28, 2017 1:51 pm

Hi Patrick,
Thank you for the hint

But I'm using VB2008 , not C/C++ or Roger language.

Any help on that too ?

Thanks again.

DenisFerrari
Phidgetsian
Posts: 12
Joined: Tue Mar 28, 2017 12:41 am
Contact:

Re: Opening a new form then returning to the original

Postby DenisFerrari » Fri Mar 31, 2017 3:33 am

Hi, just an update about my application often freezing while losing focus on a Form, locking on Bridge.Close() row :
after using Phidget21.NET.dll in place of Phidget21.NET1.1.dll, all my problems went away.
Tested on my W10 pc, using Visula Basic 2008, Visual Basic 2010 and eVisual Studio 2017 : no problems at all :)


Return to “VB .NET”

Who is online

Users browsing this forum: No registered users and 0 guests