First, for a local variable,
jObject = null;
is odd and does nothing, since the .NET memory model is
non-deterministic. Whereas there is sure is a need to
properly invoke the COM .Release() method. The outgoing
exception may be caused by an attempt to clean up the
COM reference on a non-main thread of the garbage collector.
So it might make sense to use Marshal.ReleaseComObject() or
Marshal.FinalReleaseComObject(). Typically it is wrapped in
an IDisposable interface and a clean-up pattern
Marshal.FinalReleaseComObject(_obj);
GC.SuppressFinalize(this);
http://msdn.microsoft.com/en-us/library/system.gc.suppressfinalize.aspx
----- Original Message ----
> From: John Baker <[email protected]>
> To: Programming forum <[email protected]>
> Sent: Tuesday, August 11, 2009 7:07:30 PM
> Subject: [Jprogramming] C# and JEXEServer
>
> During the last few days I have been trying to control a JEXEServer from
> C#. I have downloaded, studied
> and compiled Alex Rufon's example on the J wiki but I cannot get it to
> behave.
>
> I am using the free Visual C# Express edition. I don't believe there are
> any C# version specific issues but I could
> be wrong. The following snippet is just about the simplest possible use of
> a JEXEServer
>
> private void button1_Click(object sender, EventArgs e)
> {
> object jout;
> string jstr;
>
> JEXEServerLib.JEXEServer jObject = new JEXEServerLib.JEXEServer();
>
> jObject.Log(1);
> jObject.Show(1);
>
> jObject.Do("jRes=. 'string from J'");
> jObject.GetB("jRes", out jout);
> jstr = (string) jout;
>
> textBox.Text = jstr;
> jObject.Quit();
> jObject = null;
> }
> This almost works with the following exceptions:
>
> 1) The JEXEServer never appears despite being requested with a Show(1)
> 2) The Quit() does not shutdown the J server
> 3) Exiting the C# app leads to an invalid memory reference in J. Probably
> related to not shutting down properly.
>
> I can see J executing as j.exe shows in the process list and I can send and
> receive data from the server. I have used similiar code in VB for years and
> I judge people (Alex) have managed this from C# as well. Has anyone tried
> this recently in any of the Express compilers.
> --
> John D. Baker
> [email protected]
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm