Jason Schneekloth
11/4/2004 5:04:00 PM
Ken-
Can't thank you enough, that seems to have solved the problem wonderfully,
and still has the elegance I enjoy :)
Jason
"Ken Kolda" wrote:
> There really is no concept of a thread "holding an instance" of an object in
> a multithreaded environment like .NET. So, to marshal the call to your
> form's UI thread, you would do the following:
>
> 1) Declare a static instance of your main application form.
> 2) Use this static instance when you call Application.Run() in the Main()
> function, e.g.
>
> public class Form1 : System.Windows.Form
> {
> public static Form1 MainForm = new Form1();
>
> public static void Main()
> {
> Application.Run(MainForm);
> }
> }
>
> 3) When your server object's method is called, use MainForm.Invoke() to pass
> the call to the UI thread of the form, e.g.
>
> public class ServerObject : MarshalByRefObject, IServerObject
> {
> public void OpenMail(string addr)
> {
> if (Form1.MainForm.InvokeRequired)
> Form1.MainForm.Invoke(new mydelegate(OpenMail), new object[] {
> addr });
> else
> Process.Start("mailto:" + addr);
> }
> }
>
> Give that a shot and see if it works for you.
>
> Good luck -
> Ken
>
> "Jason Schneekloth" <JasonSchneekloth@discussions.microsoft.com> wrote in
> message news:3DDB371D-F5AD-4AF5-8559-D8354B2B7C97@microsoft.com...
> > To answer question 1....
> > yes, it's a win forms app, I was hoping that I wouldn't have to marshal
> the
> > call to the main thread, in fact, I assumed that the main thread would be
> > holding an instance of the shared object since it's an SAO and being
> > registered as a singleton, aparently I am wrong in this assumption???
> >
> > To answer question 2....
> > No, that did not seem to solve the problem, notepad would still open, but
> > the mailto call would fail....
> >
> >
> > Jason
> >
> > "Ken Kolda" wrote:
> >
> > > A couple of questions for you:
> > >
> > > 1) Is your server a windows forms app? If so, have you tried marshalling
> the
> > > call to the UI thread of your main form to see if that works?
> > >
> > > 2) I have no idea if this would have any effect, but how about if you
> set
> > > the principal on the current thread to be the windows principal before
> > > invoking "mailto:", e.g. Thread.CurrentPrincipal = new
> > > WindowsPrincipal(WindowsIdentity.GetCurrent());
> > >
> > > Ken
> > >
> > >
> > > "Jason Schneekloth" <JasonSchneekloth@discussions.microsoft.com> wrote
> in
> > > message news:C7A90291-D95A-4608-9DBF-1CB0C3850B45@microsoft.com...
> > > > Hey all-
> > > >
> > > > Posted a problem I was having a few days ago, here is a clarification
> to
> > > > that problem, I can't find any answers anywhere on how to go about
> fixing
> > > > this. I have a .NET remoting app set up, including a server, a
> client,
> > > and a
> > > > shared assembly between them....
> > > >
> > > > To test, I called:
> > > >
> > > > System.Diagnostics.Process.Start("mailto:someone@somewhere.com");
> > > >
> > > > in the server's constructor, all works just fine, pops up the default
> mail
> > > > client to handle the mailto call. No problem.
> > > >
> > > > Now....my shared assembly takes care of events between the client and
> the
> > > > server. I next make a call within the shared interface from the
> client.
> > > The
> > > > shared interface (which is implemented server-side) forwards the call
> to a
> > > > method within the server via an event which the server is registered.
> > > Inside
> > > > this method, I put:
> > > >
> > > > System.Diagnostics.Process.Start("mailto:someone@somewhere.com");
> > > >
> > > > and it fails with the following exception:
> > > >
> > > > "The requested lookup key was not found in any active activation
> context"
> > > >
> > > > So I think it's a problem using the Process.Start function from a
> remoted
> > > > call being started from the client. This isn't the case, however. If
> I
> > > > repelace the mailto with something like "notepad" all works, and
> notepad
> > > is
> > > > opened from the call originating in the client....
> > > >
> > > > System.Diagnostics.Process.Start("notepad"); <-- This works
> > > >
> > > > What is going on here? I really need this mailto functionality, and I
> dont
> > > > understand why it is not working....I can email code if someone wants
> to
> > > take
> > > > an in depth look, it's the most basic .NET remoting app you can have
> which
> > > > works with shared objects containing events....
> > > >
> > > > Oh yeah, both the client and server are running on the same machine
> and I
> > > > have no expectations of them ever being separated to different
> machines,
> > > and
> > > > I am using TCP along with binary serialization or whatever it's
> called....
> > > >
> > > > Jason
> > > >
> > >
> > >
> > >
>
>
>