Is it possible to call a method that accepts this. Handle as an argument inside the working background in C #

I am working on a standalone WinForm program in C # that uses Apache Solidworks EPDM. The program occupies the top level of the assembly and finds all links and links to files in the assembly. for example, all subnodes, part files, and drawings. Then the program checks all files from EPDM, updates data cards and checks all files on EPDM.

I have successfully executed the part of the code that finds all the links and file links and updates the data card information with the help of a background worker. This piece of code does not require access to the user interface thread. I would like to be able to add code that validates files and validates them back against a working background. The problem is that the methods used to perform validation and registration accept this. Handle as an argument. I know that accessing a UI thread from a working desktop will throw a cross-thread exception. The code does not have access to any user interface control. He needs only access to this. Handle. Is it possible to pass this. Gundle for a worker worker in a stream safe path that will not throw a cross stream exception?

This is my first use of background workers, so my knowledge is limited. Below is the code that I would like to run in the background worker.

    private void BatchCheckout(Dictionary<string, string> SelectedFiles)
    {
        try
        {
            IEdmBatchGet batchGetter = (IEdmBatchGet)vault.CreateUtility(EdmUtility.EdmUtil_BatchGet);           
            EdmSelItem[] ppoSelection = new EdmSelItem[SelectedFiles.Count];            
            IEdmFile5 aFile;
            IEdmFolder5 aFolder;
            IEdmFolder5 ppoRetParentFolder;
            IEdmPos5 aPos;
            int i = 0;

            foreach (KeyValuePair<string, string> kvp in SelectedFiles)
            {
                aFile = vault1.GetFileFromPath(kvp.Key, out ppoRetParentFolder);
                aPos = aFile.GetFirstFolderPosition();
                aFolder = aFile.GetNextFolder(aPos);
                ppoSelection[i] = new EdmSelItem();
                ppoSelection[i].mlDocID = aFile.ID;
                ppoSelection[i].mlProjID = aFolder.ID;
                i = i + 1;
            }
            batchGetter.AddSelection((EdmVault5)vault1, ref ppoSelection);
            batchGetter.CreateTree(this.Handle.ToInt32(), (int)EdmGetCmdFlags.Egcf_Lock);
            batchGetter.GetFiles(this.Handle.ToInt32(), null);
        }

        catch (System.Runtime.InteropServices.COMException ex)
        {
            MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message + "\n" + GetStackTrace(ex));
        }
    }

I read StackOverflow for many years and found the answers to every question I had. This is my first question on StackOverflow. I really hope someone will have an answer to this problem.

EDIT:

I have successfully tested AndrewK's suggestion and am happy to report that it really worked for my batch validation method. When I run my batch validation method in a background worker, I get the following COM exception:

COM- "System.__ ComObject" "EPDM.Interop.epdm.IEdmBatchUnlock2". , QueryInterface COM- IID '{F0970446-4CBB-4F0F-BAF5-F9CD2E09A5B3}' - : ( HRESULT: 0x80004002 (E_NOINTERFACE)).

, .

BatchCheckin:

    private void BatchCheckin(Dictionary<string, string> SelectedFiles)
    {
        try
        {
            int i = 0;
            IEdmFolder5 ppoRetParentFolder;
            IEdmFile5 aFile;
            IEdmFolder5 aFolder;
            IEdmPos5 aPos;
            EdmSelItem[] ppoSelection = new EdmSelItem[SelectedFiles.Count];
            IEdmBatchUnlock2 batchUnlock;

            foreach (KeyValuePair<string, string> kvp in SelectedFiles)
            {
                aFile = vault5.GetFileFromPath(kvp.Key, out ppoRetParentFolder);
                aPos = aFile.GetFirstFolderPosition();
                aFolder = aFile.GetNextFolder(aPos);
                ppoSelection[i] = new EdmSelItem();
                ppoSelection[i].mlDocID = aFile.ID;
                ppoSelection[i].mlProjID = aFolder.ID;
                i = i + 1;
            }

            batchUnlock = (IEdmBatchUnlock2)vault7.CreateUtility(EdmUtility.EdmUtil_BatchUnlock);
            batchUnlock.AddSelection((EdmVault5)vault5, ref ppoSelection);
            batchUnlock.CreateTree(0, (int)EdmUnlockBuildTreeFlags.Eubtf_ShowCloseAfterCheckinOption + (int)EdmUnlockBuildTreeFlags.Eubtf_MayUnlock);
            batchUnlock.Comment = "Updates";
            batchUnlock.UnlockFiles(0, null);
        }

        catch (System.Runtime.InteropServices.COMException ex)
        {
            MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message + "\n" + GetStackTrace(ex));
        }
    }

, vault7.CreateUtility. BatchCheckin BatchCheckout. vault7.CreateUtility . , EdmUtility EdmUtil_BatchUnlock BatchCheckin. AndrewK?

UPDATE:

COM, batchUpdate IEdmBatchUnlock2 IEdmBatchUnlock. :

    private void BatchCheckin(Dictionary<string, string> SelectedFiles)
    {
        int i = 0;
        IEdmFolder5 ppoRetParentFolder;
        IEdmFile5 aFile;
        IEdmFolder5 aFolder;
        IEdmPos5 aPos;
        EdmSelItem[] ppoSelection = new EdmSelItem[SelectedFiles.Count];
        IEdmBatchUnlock batchUnlock = (IEdmBatchUnlock)vault7.CreateUtility(EdmUtility.EdmUtil_BatchUnlock);

        try
        {
            foreach (KeyValuePair<string, string> kvp in SelectedFiles)
            {
                aFile = vault5.GetFileFromPath(kvp.Key, out ppoRetParentFolder);
                aPos = aFile.GetFirstFolderPosition();
                aFolder = aFile.GetNextFolder(aPos);
                ppoSelection[i] = new EdmSelItem();
                ppoSelection[i].mlDocID = aFile.ID;
                ppoSelection[i].mlProjID = aFolder.ID;
                i = i + 1;
            }               
            batchUnlock.AddSelection((EdmVault5)vault5, ref ppoSelection);
            batchUnlock.CreateTree(0, (int)EdmUnlockBuildTreeFlags.Eubtf_ShowCloseAfterCheckinOption + (int)EdmUnlockBuildTreeFlags.Eubtf_MayUnlock);
            batchUnlock.Comment = "Release to Production ECO";
            batchUnlock.UnlockFiles(0, null);
        }

        catch (System.Runtime.InteropServices.COMException ex)
        {
            MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message + "\n" + GetStackTrace(ex));
        }
    }

, IEdmBatchUnlock2. IEdmBatchUnlock2 COM, , COM, . IEdmBatchUnlock COM .

+4
1

0 . , . .

        batchGetter.AddSelection((EdmVault5)vault1, ref ppoSelection);
        batchGetter.CreateTree(0, (int)EdmGetCmdFlags.Egcf_Lock);
        batchGetter.GetFiles(0, null);
+1

Source: https://habr.com/ru/post/1674776/


All Articles