Book a Demo

Author Topic: something stealing focus when I am using Interop.dll  (Read 5022 times)

bakawakalaka

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-1
    • View Profile
something stealing focus when I am using Interop.dll
« on: January 30, 2019, 02:50:50 am »
Hi, I'm trying to create add-in (using c# with winforms) whith two forms (settings form and progress form) that just Save all daigram images in .eap file to directory. I do it using multithreading.
This is especially annoying when I'm starting an EA, open my Add-in, start save images, switch to do something else (for example write in outlook) and then somehow I lost focus. I'm trying set ShowWithoutActivation field to true, Focused field to false on the forms but its don't work.
It's just when I using EA classes from Interop.dll. I tried example when I'm removed all code that using EA.Interop in my "SaveImagesAsync" method  and added Thread.Sleep() for pretend work in add-in and then focus is not stealing! Then I created ConsoleApplication that just do work of my add-in (save all images from .eap file) and then focus is stealing!

Had anyone this problem? How I can solve this?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: something stealing focus when I am using Interop.dll
« Reply #1 on: January 30, 2019, 05:20:26 am »
Do you know what exactly you are doing when the focus is stolen?

I'm not saying I never saw this type of behavior, but is has never been an issue for me.
Feels like you must be doing something I'm not.

Geert

bakawakalaka

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-1
    • View Profile
Re: something stealing focus when I am using Interop.dll
« Reply #2 on: January 31, 2019, 11:02:20 pm »
Do you know what exactly you are doing when the focus is stolen?

I'm not saying I never saw this type of behavior, but is has never been an issue for me.
Feels like you must be doing something I'm not.

Geert

Well, this is source code part that I'm using (whatever if I using it in async method in winform or just in main in console). It's a messy but it reproduce problem when I save ~400 images. it have a little hack - I reopen eap file because Interop.EA library can just throw HRESULT: 0x80010105 (RPC_E_SERVERFAULT) error.

Code: [Select]
            List<string> diagrams;
            using (var con = new OleDbConnection(str))
            {
                con.Open();
                var diaobjects = con.Query<t_diagramobjects>(SQLQueries.GetDiagramObject).Select(q => q.Diagram_ID)
                    .Distinct().Except(new int[] { 0 }).ToList();
                diagrams = con.Query<t_diagram>(SQLQueries.GetDiagram)
                   .Where(q => diaobjects.Contains(q.Diagram_ID))
                   .Select(q => q.ea_guid).ToList();
            }

            int i = 0;
            EA.Repository rre;
            EA.Project interf;

            rre = new EA.Repository();
            rre.OpenFile(patch_to_eap_file);
            interf = rre.GetProjectInterface();
            foreach (var dia in diagrams)
            {
                var tmpPath = ($"{imgDirPath}{dia}.png");
                interf.PutDiagramImageToFile(dia, tmpPath, 1);
                Console.WriteLine($"{i}" + tmpPath);

                if (i == 50)
                {
                    rre.CloseFile();
                    rre.Exit();
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    i = 0;
                    rre = new EA.Repository();
                    rre.OpenFile(patch_to_eap_file);
                    interf = rre.GetProjectInterface();
                }
                i++;
            }

            rre.CloseFile();
            rre.Exit();
            GC.Collect();
            GC.WaitForPendingFinalizers();

            Console.WriteLine("end");
            Console.Read();
« Last Edit: January 31, 2019, 11:48:40 pm by bakawakalaka »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: something stealing focus when I am using Interop.dll
« Reply #3 on: February 01, 2019, 01:13:50 am »
Ah, it's probably the PutDiagramImageToFile(). That one requires EA to open the diagram.
You can avoid that by using an XMI export I believe. Package.exportToXMI() has parameter to include diagrams.
If you set that to true it will export the images of all diagrams in the package to separate image files.

Geert

PS. Why are you using your own connection to query the database? I always just use Repository.SQLQuery()

bakawakalaka

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-1
    • View Profile
Re: something stealing focus when I am using Interop.dll
« Reply #4 on: February 01, 2019, 10:20:01 pm »
Ah, it's probably the PutDiagramImageToFile(). That one requires EA to open the diagram.
You can avoid that by using an XMI export I believe. Package.exportToXMI() has parameter to include diagrams.
If you set that to true it will export the images of all diagrams in the package to separate image files.

Geert

PS. Why are you using your own connection to query the database? I always just use Repository.SQLQuery()

Am I right that you mean Proect.ExportPackageXMIEx()? I tried it. it's still steals focus but less than before(and works much faster!). Maybe if I'll not found something better(I think about using global hook now) I stay on this solution

I'm using LinqToDB. It's much easer then parsing data from xml.
« Last Edit: February 01, 2019, 10:43:31 pm by bakawakalaka »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: something stealing focus when I am using Interop.dll
« Reply #5 on: February 02, 2019, 01:55:57 am »
Ah, it's probably the PutDiagramImageToFile(). That one requires EA to open the diagram.
You can avoid that by using an XMI export I believe. Package.exportToXMI() has parameter to include diagrams.
If you set that to true it will export the images of all diagrams in the package to separate image files.

Geert

PS. Why are you using your own connection to query the database? I always just use Repository.SQLQuery()

Am I right that you mean Proect.ExportPackageXMIEx()? I tried it.
Yes, sorry. I have an exportToXMI() method in my Package wrapper class that calls that Project.ExportPackageXMI() method.

Geert