-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: SitaramanM
Message 10 in Discussion

Hi   Using the process class anyways was not a good idea.  process Class makes sense 
when you want to execute non-.Net aplications.  In the case of pure .net applications 
you should use the .Net techniqueswhich are there.  For example you can use the 
Assembly.Load method to load the assembly and then instantiate the type inside the 
assembly   For example i might have a winform application which might need to be 
started(or for that matter a console application).  In that case you can acheive the 
startup of the applicatiuon as follows   Sub Main()
        Try
            Dim l_objCalledWinFormAppAssembly As [Assembly]
            'Note :
            ' Load the SLN File
            ' Compile the Solution using Rebuild All
            ' Modify the value of p_strCalledAssemblyFileName to store the correct 
path of the winform assembly exe file
            ' Run the application
            Dim p_strCalledAssemblyFileName As String = 
"C:\temp\Dummy_CallingOneAppFromAnotherAppUsingAssemblyLoad\CalledWinformApp\bin\CalledWinformApp.exe"
            Dim l_objCalledWinFormApppForm As Object
            Console.WriteLine("Loading the Assembly")
            l_objCalledWinFormAppAssembly = 
[Assembly].LoadFrom(p_strCalledAssemblyFileName)
            Console.WriteLine("Assembly Loaded.  Creating an instance of Form1")
            l_objCalledWinFormApppForm = 
l_objCalledWinFormAppAssembly.CreateInstance("CalledWinformApp.Form1")
            Console.WriteLine("Form1 Instance Created. Calling Button Click function")
            l_objCalledWinFormApppForm.Button1_Click(Nothing, Nothing)
            Console.WriteLine("Button Click Event Called.  Now calling the function in 
the other program which should throw an Exception with a Custom Message")
            Try
                l_objCalledWinFormApppForm.fnThrowException()
            Catch p_objException As Exception
                Console.WriteLine("This Exception SHOULD happen.  Check Out the 
Message getting printed as set in the Form1.fnThrowException function")
                'Note that Im using p_objexception.InnerException.source And Not 
p_objexception.Source. When u use
                ' assembly.load then the exception object source will be mscorlib 
which will wrap the actual exception
                ' thrown
                Console.WriteLine("Source : " & p_objException.InnerException.source)
                'Note that Im using p_objException.InnerException.Message And Not 
p_objexception.Message. When u use
                ' assembly.load then the exception object source will be mscorlib 
which will wrap the actual exception
                ' thrown
                Console.WriteLine("Source : " & p_objException.InnerException.Message)
            End Try
            Console.WriteLine("")
        Catch p_objException As Exception
            Console.WriteLine("This Exception should NOT have happened.  Some problem 
Try to Debug...")
            Console.WriteLine(p_objException.Message)
        End Try
        Console.ReadLine()
    End Sub   Here note that from a console application im calling a Windows Forms.  
The advantage is the code runs in the same process as of the calling application(the 
same appdomain infact , though if you want you can load it in a separate appdomain for 
application isolation), and you can seamlessly call the functionalities   Also 
attaching the Zip version of the whole solution for your reference. Download,  copy, 
open the sln in VS.Net and make only one change in the Module1.vb file as follows      
       ' Load the SLN File
            ' Compile the Solution using Rebuild All
            ' Modify the value of p_strCalledAssemblyFileName in the main function of 
Module1.vb to store the correct path of the winform assembly exe file
            ' Run the application   The demo program has excepion handling implemented 
  hth   regards,   sr
View Attachment(s):
http://groups.msn.com/BDotNet/_notifications.msnw?type=msg&parent=1&item=6449
-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/BDotNet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to