I've created two packages file as


the functions InstallNET[] and ReinstallNET[], both of them are used in the upper packages, when ReinstallNET is invoked in current package, the objects created previouly in the other packages shall crash, vise versa. and ReinstallNET is nessary because dead link might comes up unexpectedly now and then. How should I do to avoid the conflicts or make them working in independent workspaces? Thanks!


1 Answer 1


If there be no ways to restrict each package has indepent NETLink workspace, what I could do is to make sure that the NETLink instance runs only one time through the invoking.

checkupNETLink[] :=
     Module[ {bIsLoaded,result},
        (*check NETLink Package*)
         bIsLoaded = Length@Options@InstallNET > 0;
         If[ !bIsLoaded,
         result = Length@Options@InstallNET > 0;

then going to check whether the NETLink instance is in Links and system processes lists or not.

checkupNETInstance[] :=
    Module[ {bIsInLinks,bIsInProcesses,result},
        (*check up NETLink*)
        If[ !checkupNETLink[],

        (*check Links list*)
        bIsInLinks = Length@Select[
           Length /@ (StringPosition[#, "InstallableNET"] & /@ (#[[1]] & /@ 
                Links[])), # > 0 &] > 0;

        (*check in case of process terminated unexpectedly but Links might have dead link*)
        bIsInProcesses = Length@Select[
           Length /@ (StringPosition[#, 
                "InstallableNET"] & /@ (First@Take[#, {-3}] &@
                  Values@#[[1]] & /@ SystemProcesses[])), # > 0 &] > 0;

        (*Uninstall to kill dead link*)
        If[ Or[!bIsInLinks,!bIsInProcesses],

        result = BooleanQ@NETObjectQ@NETNew["System.Windows.Forms.Form"];

when to setup NETLink instance,checkupNETInstance[] should be invoked. Hope there be better codes on this problem.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.