Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Running code in a different appdomain

Running code in a different appdomain

Scheduled Pinned Locked Moved C#
question
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    laserbaronen
    wrote on last edited by
    #1

    Is there any way i can run a code snippet inside a different appdomain? (So i can load the same assembly twice for some reason)

    public class MyFooBarAssembly
    {
    public myFooBarAssembly(string loadFrom)
    {
    assembly = AssemblyName.GetAssemblyName(loadFrom);

    }
    AssemblyName assembly;
    
    // This is the method i want to run in a different appdomain)
    public AssemblyName\[\] GetReferencedAssemblies()
    {
         return Assembly.ReflectionOnlyLoadFrom(assembly.CodeBase).GetReferencedAssemblies();
    }
    

    }


    betonglasermur.FeedDwarf(pur_is, 17);
    ProcessStartupInfo.AintNotCreateNoWindow = (false && !true) != (true || false) ? false == true ? true : false : (true != false && false);

    Morgonen är tröttmans mecka

    S 1 Reply Last reply
    0
    • L laserbaronen

      Is there any way i can run a code snippet inside a different appdomain? (So i can load the same assembly twice for some reason)

      public class MyFooBarAssembly
      {
      public myFooBarAssembly(string loadFrom)
      {
      assembly = AssemblyName.GetAssemblyName(loadFrom);

      }
      AssemblyName assembly;
      
      // This is the method i want to run in a different appdomain)
      public AssemblyName\[\] GetReferencedAssemblies()
      {
           return Assembly.ReflectionOnlyLoadFrom(assembly.CodeBase).GetReferencedAssemblies();
      }
      

      }


      betonglasermur.FeedDwarf(pur_is, 17);
      ProcessStartupInfo.AintNotCreateNoWindow = (false && !true) != (true || false) ? false == true ? true : false : (true != false && false);

      Morgonen är tröttmans mecka

      S Offline
      S Offline
      Simon P Stevens
      wrote on last edited by
      #2

      First create the new domain: AppDomain myNewAppDomain = AppDomain.CreateDomain("MyNewAppDomain"); Then create the class you want to run code on in the new app domain. Object myObjectInADifferentDomain = myNewAppDomain.CreateInstanceAndUnwrap(myAssemblyName, myTypeName); Then just call the methods on it as you would normally with reflection.

      Simon

      S 1 Reply Last reply
      0
      • S Simon P Stevens

        First create the new domain: AppDomain myNewAppDomain = AppDomain.CreateDomain("MyNewAppDomain"); Then create the class you want to run code on in the new app domain. Object myObjectInADifferentDomain = myNewAppDomain.CreateInstanceAndUnwrap(myAssemblyName, myTypeName); Then just call the methods on it as you would normally with reflection.

        Simon

        S Offline
        S Offline
        Simon P Stevens
        wrote on last edited by
        #3

        Oh, sorry, I didn't read your question properly. You can use newAppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate); and just pass in a CrossAppDomainDelegate for the method you want to run. That will allow you to execute your method in a different domain. (You might have to change your method slightly to match the CrossAppDomainDelegate)

        Simon

        L 1 Reply Last reply
        0
        • S Simon P Stevens

          Oh, sorry, I didn't read your question properly. You can use newAppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate); and just pass in a CrossAppDomainDelegate for the method you want to run. That will allow you to execute your method in a different domain. (You might have to change your method slightly to match the CrossAppDomainDelegate)

          Simon

          L Offline
          L Offline
          laserbaronen
          wrote on last edited by
          #4

          Thanks! exactly what i needed ;)


          betonglasermur.FeedDwarf(pur_is, 17);
          ProcessStartupInfo.AintNotCreateNoWindow = (false && !true) != (true || false) ? false == true ? true : false : (true != false && false);

          Morgonen är tröttmans mecka

          S 1 Reply Last reply
          0
          • L laserbaronen

            Thanks! exactly what i needed ;)


            betonglasermur.FeedDwarf(pur_is, 17);
            ProcessStartupInfo.AintNotCreateNoWindow = (false && !true) != (true || false) ? false == true ? true : false : (true != false && false);

            Morgonen är tröttmans mecka

            S Offline
            S Offline
            Simon P Stevens
            wrote on last edited by
            #5

            My pleasure :) (If only everyone was polite like you)

            Simon

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups