Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi everybody

i generate a form codes using CodeDom, and i compile it successfully but my problem is i get console based form app'!!!

how can i eliminate that console background??

thanks in advance
Posted

OK, as OP expressed interest in my alternative way of working with dynamically compiled assemblies, I'm starting to sketch the design.

Introduction: I used to develop some designs for adding assemblies dynamically or during run-time. One option is to add assemblies from executable files. Such assemblies could be loaded during run-time once and until the end of the run-time of the host application, which is easy (I call it plug-in architecture) or periodically unloaded or loaded, which is more difficult, because there is no way to unload a loaded assembly — conceptually, by .NET design, so System.AppDomain should be used (let's call it dynamic modular design). Another opportunity is to generate assembly from code DOM into host's memory. Let's call it IDE design. I used IDE design to create a conventional C# (or any other .NET language-based calculator) and also a symbolic calculator, a part of my Computer Algebra System (CAS) calculator. As the calculator design does not disclose my know-how on the CAS, I can share it. Naturally, the IDE design should only work with Application Domains, because the IDE should allow for unlimited number of re-compilation. In essence, the host application provides the host for building and running small applications (let's call them Applets) in the same process as the host, but in different Application Domain and thread(s).

Interfaces with plug-ins or Applets and System.AppDomain: Take a look at my recent Answer to a different Question: Create WPF Application that uses Reloadable Plugins...[^]. Please understand that some more advanced aspect of this discussion are highly controversial and needs some development. Here we only need to discuss the IDE design which is much more certain and well-defined compared to the very indeterminate requirements of Ven's project which is probably in an early inception phase. Important point in this reference for IDE design is: how to define interface with the plug-in (in our case it will be the Applet, so mentally replace "plug-in interface" with "Applet interface"), how to recognize and instantiate the entry class in the Applet by the host's code and how to work across the boundary beteen different Application Domains. Let's assume it is more or less clear.

Applet hosting interface: Lets go back to IDE design. The Applet hosting interface should do something like that: it should be able to get some source code of the future Applet in the form of one or more strings each representing the input file. Code DOM has the options to compile such set of source codes. Another option to be used is to compile it into memory. The result of compilation should (errors, code line numbers, etc.) should be delivered to the host through the Application Domain boundary. Another method of the Applet hosting interface would be to "run" some method of the complied applet and re-direct output in some way accessible by the host. Let's consider such output.

Applet output: This way should be designed, but the main principle is working via IPC, because the data should be passed via Application Domain boundary (from Applet's Application Domain to host Application Domain), and also dispatched to the host's UI thread. In my projects, the output was simply a string (in one project representing HTML passed to Web browser control). For such simple data transfer a simplified method of System.AppDomain can be used. For more complex and time consuming data transfer process a blocking queue based on transport IPC should be used: WCF or remoting, based on Windows named pipes. The dispatching of events to the UI thread should be done entirely on the host Application Domain side, see: Control.Invoke() vs. Control.BeginInvoke()[^], Problem with Treeview Scanner And MD5[^].

Applet interface: How Applet hosting interface should identify what Applet method to run. It should be defined as a special Applet interface and, after compilation, instantiated by the host (on Applet Application Domain side). It is done using the same principles described in the section "Interfaces with plug-ins or Applets and System.AppDomain".

General order of operation: This is the main cycle of the host application. The user types the code of applet (it can be simplified by adding some common constructs automatically) or load the code from external file(s). The host should have a singleton (http://en.wikipedia.org/wiki/Singleton_pattern[^]) object of the type System.AppDomain initialized lazily (http://en.wikipedia.org/wiki/Lazy_evaluation[^]). If previously created instance exists, it should be unloaded. This is a whole point of using Application Domains, otherwise inability to unload any assemblies would created a strong memory leak. New Application Domain is created, source code and options (in particular, ID of computer language!) delivered to the instance of the Applet host through the Application Domain boundary. AppDomain.GetData/SetData would work fine for these purposes. Code is compiled into memory in the Applet's Application Domain, errors delivered back to the host. The errors can be presented to the host's UI in the same way as in Visual Studio. If the build is successful, the new Assembly appears in the memory space of the Applet's Application domain. Applet host interface try to identify entry point object according the the schema described above, using Applet interface. If this procedure is failed, the status is delivered back to the host's Application Domain and presented in the UI. If the reference to the Applet host is obtained (entry class implementing Applet interface instantiated), Applet entry point is run, output is delivered to the host. The compilation and run of Applet should be done in the separate thread created in the Applet's Application host from the very beginning. The host need a way abort this thread through the Application Domain boundary. What is good, any problems of incomplete reclaiming of any resources in the Applet's Application Domain and not critical, because this domain will be unloaded in cycle. When Applet interface code run cycle is finished, the event is delivered through the Application Domain boundary to the host. The host UI enables the user to start a new compile/run cycle.

—SA
 
Share this answer
 
Comments
Espen Harlinn 17-Mar-11 15:51pm    
my 5 - impressive effort. Wouldn't it make sense to use the initial AppDomain purly for control and management of the other AppDomains?
Sergey Alexandrovich Kryukov 17-Mar-11 16:11pm    
Thank you, Espen.
By the way, 5 from who?
As to you suggestion: I don't see the difference. This is what I suggested. There is a lot more to that. Basically, the approach is to do all UI in the initial App Domain, and load/build/execute the Applet in another one. This is unavoidable because there is not way to unload assembly; only AppDomain can be unloaded. All domain management is in the initial one.
--SA
Espen Harlinn 17-Mar-11 17:09pm    
I'm fairly certain saw it rotating before scrolling down to add my comment :)
Sergey Alexandrovich Kryukov 17-Mar-11 17:17pm    
I believe. That small rotating thing is such a sly beast... :-)
Thank you, Espen.
--SA
dariush_ha 18-Mar-11 11:32am    
thank u for ur post-back
guess need some time to get things up :)
i'll return to ur post when i study some more, and have enough knowledge about this, but i'll soon ...
I believe there's an option in a class somewhere called 'target' (not platform) which should be set to WinExe.

The method suggested by John might not work (dunno for sure), because the suggested code does not hide the console if you change a Form Project output to Console application.
 
Share this answer
 
Comments
dariush_ha 16-Mar-11 10:33am    
yes that do not work, because i already had them in my code!
Sergey Alexandrovich Kryukov 16-Mar-11 13:30pm    
This is the only correct Answer to the question, which has nothing to do with CodeDom. My 4.
This Answer is not clear though.
--SA
Sergey Alexandrovich Kryukov 16-Mar-11 13:41pm    
So, I added some clarification, hope it makes sense,
--SA
// Define parameters to invoke a compiler
System.CodeDom.Compiler.CompilerParameters _CompilerParameters =
        new System.CodeDom.Compiler.CompilerParameters();

// by entering  ' /target:winexe ' we will all set to go!!
CompilerParameters.CompilerOptions = "/optimize /target:winexe";


thanks to ' nbgangsta ' for giving me the clue!!

if we have a System.CodeDom.Compiler.CompilerParameters object, we can set target option in this object's CompilerOptions parameter [ see above ].

this option by default is ' /target:exe ' which create an ' .exe ' file

for further information see this[^]
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 16-Mar-11 13:42pm    
Not clear how it is related to console you've been complaining about...
Know the difference between target and type.
[EDIT] After Dariush's clarification, I understand... the above two lines can be disregarded.
--SA
dariush_ha 16-Mar-11 13:47pm    
i know the diffrnc between type and target!!!!!!!!:)

take a second look at the topic, i'm using CodeDom and i generate windows form code [ note : my app does that ] and then my app tries to compile generated codes!!

any question??
Sergey Alexandrovich Kryukov 16-Mar-11 13:51pm    
Absolutely. I did not understand you. Sorry, I think your formulation of the Question is not clear enough, I've been confused... I'll remove my Answer.
--SA
Sergey Alexandrovich Kryukov 16-Mar-11 13:53pm    
I removed my Answer...

By the way, I do host dynamically loaded assembly as a library, and run in in the host process. I developed different ways, this is the best. Entry point found by some interface. http://www.codeproject.com/Answers/168158/Create-WPF-Application-that-uses-Reloadable-Plugin.aspx Also, do you know that you need to use AppDomain if need to load your dynamically compiled assembly many times (as you cannot unload it)? Ask me if interested.

--SA
dariush_ha 16-Mar-11 14:17pm    
yeah i want to know, it's interesting
Try putting this in your Main method:

C#
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MyDomForm()); 
 
Share this answer
 
Comments
dariush_ha 16-Mar-11 10:34am    
it won't work dude, i already have them in my code!
Sergey Alexandrovich Kryukov 16-Mar-11 13:39pm    
John, I know why it's not working. The question is quite misleading. I answered, please see.
(I did not vote this time.)
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900