Different ImageViewerControl in multiple windows

We have an application that you can select the camera/recording an launch another window in order to play it.

The second window contains an imageControlViewer, the user can create multiple windows with different camera/recordings information but when a window has been created and closes the new one has an excepction at imagecontrolviewer.Initialize() saying: Can’t be created more than one instance System.Windows.Application at the same AppDomain.

en System.Windows.Application..ctor()

en VideoOS.Platform.SDK.UI.DirectX.ImageViewerDirectX..ctor()

en VideoOS.Platform.SDK.UI.SDKImageViewerControl.Create()

en VideoOS.Platform.SDK.PlatformImageViewerControl.Initialize()

en MKVTransact1.frmSearchDirect.VideoPlaybackConnect() en C:

How the imageViewerControl has to be manage to work in multiple windows?

Thanks in advance for your help

If you create each..

_imageViewerControl[i] = ClientControl.Instance.GenerateImageViewerControl();

each should be its own object and initializable.

(here I imagine an array, but any structure that allows multiple objects of the same class should be fine.)

If this is not sufficient answer or hint I would like you to share a snippet of your code so that I can see what it is your code does..

Hello,

I have the same issue. I try to explain better what I found. In our software ImageViewControl is opened on a pop-up window. You can open several instances without any problem. If you close all popup and re-open a new instance, it fail with the exception.

I cannot reproduce. I made a “minimal” implementation of what you have described. If you, and anybody who experienced similar, could test this and give me feedback, if it works for you, I would appreciate it.

http://download.milestonesys.com/MIPSDK/Samples/ManyImageViewerControls.zip

(or built executable)

http://download.milestonesys.com/MIPSDK/Samples/ManyImageViewerControls_exe.zip

If it works for you as it does for me I hope you can help me find out what more is needed to trigger the issue..

Thank you for your replays.

Bo, I’ve tried your code, and when I clase the imageviewcontrol window I get a System.NullReference exception.

This could be easy if i can send you part of the code. I will try to show you some parts:

Form1 → This form load the configuration of server and camera names and the user select the camera to connect

Form2

-> onLoad the connection to milestone is done

 Uri uri = new UriBuilder("http://" + hostName).Uri;
            if (!VideoOS.Platform.SDK.Environment.IsServerConnected(uri))
                VideoOS.Platform.SDK.Environment.AddServer(uri, CredentialCache.DefaultNetworkCredentials);
            //tbResults.Text = "Login " + uri.AbsoluteUri + " ..." + Environment.NewLine;
            try
            {
                if (!VideoOS.Platform.SDK.Environment.IsLoggedIn(uri))
                    VideoOS.Platform.SDK.Environment.Login(uri);
            }

Then connect to the playback:

if (PlaybackControllerFQID == null)
                    PlaybackControllerFQID = VideoOS.Platform.ClientControl.Instance.GeneratePlaybackController();
                
                ImageViewerControl = VideoOS.Platform.ClientControl.Instance.GenerateImageViewerControl();
                ImageViewerControl.CameraFQID = SearchCameraByName(CameraName).FQID;
                ImageViewerControl.PlaybackControllerFQID = PlaybackControllerFQID;
                ImageViewerControl.Dock = DockStyle.Fill;
 
                ImageViewerControl.ClickEvent += new EventHandler(_imageViewerControl1_ClickEvent);
                VideoPanel.Controls.Clear();
                VideoPanel.Controls.Add(ImageViewerControl);
                ImageViewerControl.SendToBack();
                //ImageViewerControl.CameraFQID = SearchCameraByName(CameraName).FQID;
                ImageViewerControl.Initialize();
                ImageViewerControl.Connect();
                ImageViewerControl.Selected = true;

And you can create from form1-> form2 as many windows to same/different recordings as you want

OnFormClosing disconnection from milestone connection and imageviewercontrol and playbackcontrol is done:

VideoOS.Platform.SDK.Environment.RemoveAllServers( );

  if (\_imageViewerControl1 != null)

  {

    \_imageViewerControl1.Disconnect();

    \_imageViewerControl1.Close();

    \_imageViewerControl1.Dispose();

   // \_imageViewerControl1 = null;

  }

  if (\_playbackUserControl != null)

    \_playbackUserControl.Close();

Then if new Form2 is created, the error is shown at _imageViewerControl1.Initialize();

I hope this helps to explain the problem.

Thanks!

You say you tested my code and it gives you the exception. I am sorry, but then I do not see how your extended code will be better.

Are you using MIP SDK 2019R1? If not, please upgrade and use 2019 R1.

Please change the design of your solution. Please initialize and login at start-up, from your description in form1, do not login again and again as you do every time you open a new form2. (You can see this is what I do in my minimal sample.)

PS. If this does not lead to a solution I will create a support case and you can upload source code for me to see on a Milestone FTP.

Hi again,

Thank you for your tips, I tried but the application is still not working.

Why if the ImageViewControl is disconnected and disposed loses the capability of be initialize again?

Why an Unitilize() (or something like that) could not be implemented for that object?

Any solution I could try?

Thanks,

Cristina

I have to be sure so I ask for clarification. When you run my code unmodified do you see an exception?

http://download.milestonesys.com/MIPSDK/Samples/ManyImageViewerControls.zip

(or built executable)

http://download.milestonesys.com/MIPSDK/Samples/ManyImageViewerControls_exe.zip

Hello,

your solution seems works correctly and does not crash, but, if you do not disconnect on window closing, stream is still alive and you see on Task Manager that network usage of process is continue growing.

I do not see that. The moment the form, including the ImageViewerControl, is closed I see the network traffic stop (or reduce back to as it was before).

If you observe traffic then try this on closing the form..

private void OnClose(object sender, FormClosedEventArgs e)
{
    if (_imageViewerControl1 != null)
    {
        _imageViewerControl1.Disconnect();
        _imageViewerControl1.Close();
        _imageViewerControl1.Dispose();
        _imageViewerControl1 = null;
    }
}

This code is usually what the samples use if readying the control for recreation with another camera.

Hello,

this is exactly the issue. If I do not close and dispose imageviewer component I can open and close form without any crash. If you add closing, as you suggested, issue appear.

In order to reproduce the issue on sample (with OnClose event):

  • Open a camera view form
  • Close the form
  • Open a camera view form, Exception is raised.

So if you add the OnClose mentioned above in my sample the sample starts crashing for you? (I cannot reproduce)

Hello,

After some investigation I discover that the issue appear only in debug in Visual Studio 2019. Launching exe directly or in Visual studio 2017, it works correcly.

I am having exactly the same problem using the 2019R2 SDK and Visual Studio 2019, also only when debugging. I open a form and create an ImageViewerControl, show a camera feed in the ImageViewerControl, close the form (with the OnClose cleanup code), then do the same thing again, and when Initalize() is called the second time I get this:

An unhandled exception of type 'System.InvalidOperationException' occurred in PresentationFramework.dll
Cannot create more than one System.Windows.Application instance in the same AppDomain

Any plans on a fix for this?

After a closer investigation it was found that there is an issue that can be experienced while debugging ImageViewerControl using Visual Studio in the 2019 version.

Milestone Development has changed the ImageViewerControl implementation so that the debugging issue with Visual Studio 2019 will not occur in future versions of the MIP SDK.

MIP SDK 2019R3 will include this fix. MIP SDK 2019R3 is planned to be released in October. (Plan is subject to change without notice.)

@Bo Ellegård Andersen (Milestone Systems)​

A bit late to the party but I was able find a work around for this issue by disabling “UI Debugging Tools for XAML” (see screenshot below).

Open Visual Studio, navigate to Tools > Options > Debugging and uncheck “Enable UI Debugging Tools for XAML” option. Click “OK” to save and test.

Thanks,

Dani