none
Start and Run Process from Memory RRS feed

Answers

All replies

  • No, not as a separate process.  AFAIK, an executable would need to be written to disk to launch it as a separate process.

    However, there are ways to create assemblies or even just single methods dynamically at runtime in memory, and you can run that code using separate threads in your own process.

    AssemblyBuilder:  http://msdn.microsoft.com/en-us/library/system.reflection.emit.assemblybuilder.aspx
    DynamicMethod:  http://msdn.microsoft.com/en-us/library/system.reflection.emit.dynamicmethod.aspx



    • Marked as answer by Matt Fomich Thursday, October 9, 2008 11:43 PM
    Thursday, October 9, 2008 10:52 PM
  • Since you already have the file, there's no need to load it yourself.  Just use Process.Start().
    Hans Passant.
    Thursday, October 9, 2008 11:33 PM
    Moderator
  • File is an embedded file, I would prefer not to have to write it to disk--just want to be able execute it on the fly, if needed.
    Thursday, October 9, 2008 11:40 PM
  • Hey, thanks BC, DynamicMethod is just what I was looking for.  It looks like it is available in .Net 2.0 as well.

    Regards to all,

    -Matt-
    Thursday, October 9, 2008 11:43 PM
  •  If i understand the Original question:
    " Is there a way to save a file to memory, and run it? "

    Yes, atleast i have done it:

    My requirement was: to write out/create a file to be used by some parts of the programm.

    The Production server requirement was that, Application wasn't allowed to "create file" in the space.
    In otherwords, ASP.net application didn't have enough permisions to write the file to the server space.

    Hence, the need to create file on the fly in memory and have the application read from there.

    So whatever your requirement is: Yes, you can put file into the Memory and read it from there:

    Here

    1) Create it in memory -Note the MemoryStream class (U can read about it) :
    Private Memoryspace as New MemoryStream

    Dim Obj as New = StreamWrite(Memoryspace)

    Obj.write(Content.toString)

    Obj.flush()
    Obj.close()

    2) Read it From Memory somewhere in your APplication. Requirement is you have acces to the obj " Memoryspace"
        That is why i put it out there to its availabe to methods below and its still private

    Dim ByteArray() as Byte = Memoryspace.ToArray
    Memoryspace.flush
    Memoryspace.close

    Now, the content you read is in ByteArray() and you can do whatever you needed
    Friday, October 10, 2008 2:53 PM