1

How will such a starting point for WPF?

[STAThread]
    static void Main() 
    {      

        ClientClass remService  = new ClientClass();
        ObjRef obj = RemotingServices.Marshal(remService,"TcpClient");

        // Create apllications MainForm
        ClientApp frmMain = new ClientApp();

        // provide marshaled object with reference to Application
        remService.theMainClient = ( IClientApp) frmMain;

        System.Console.WriteLine("Please press ENTER to exit...");
        System.Console.ReadLine();      


        // Application closed...

        Application.Run(frmMain);


        RemotingServices.Unmarshal(obj);
        RemotingServices.Disconnect(remService);

    }

In winforms marshalling works correctly, I would like convert it and WPF.

    [System.STAThreadAttribute()]
    [System.Diagnostics.DebuggerNonUserCodeAttribute()]
    static void Main()
    {
        OperClass remService = new OperClass();
        ObjRef obj = RemotingServices.Marshal(remService, "TcpClient");

        // Create apllications MainForm
        MainWindow frmMain = new MainWindow();
        App app = new App();
        // provide marshaled object with reference to Application
        remService.TheMainOper = (IOperApp)frmMain;

        Console.WriteLine("Please press ENTER to exit...");
        Console.ReadLine();


        // Application closed...
        app.InitializeComponent();
        app.Run();

        RemotingServices.Unmarshal(obj);
        RemotingServices.Disconnect(remService);
    }

I did so, but I'm not quite sure what is right, because the program works is not entirely correct.

pastebin.com/u/Jinfaa CODE http://screencast-o-matic.com/watch/clniI54tY VIDEO

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Feor
  • 259
  • 3
  • 15
  • Did you write that code yourself, or did you use a converter? It looks like you used a converter. I would recommend against that. – Zenexer Feb 08 '12 at 02:07
  • In that case, you should remove the DebuggerNonUserCode attribute. – Zenexer Feb 08 '12 at 02:11
  • What are you trying to do via remoting? It's difficult to tell what the purpose of that is, and that seems to be what is causing the issue, based on your description of the problem. – Zenexer Feb 08 '12 at 02:15
  • The program is still not working correctly. That is when I use remotingservice.marshal. http://screencast-o-matic.com/watch/clniI54tY – Feor Feb 08 '12 at 02:17
  • update is sent to the server interface does not work. – Feor Feb 08 '12 at 02:17
  • http://pastebin.com/u/Jinfaa's codes of programs. In winforms all right. – Feor Feb 08 '12 at 02:18
  • I'm unsure what purpose the remoting serves. I don't believe that is required. – Zenexer Feb 08 '12 at 02:24
  • But the server is properly working with winforms. It turns out does not work with WPF? – Feor Feb 08 '12 at 02:26
  • I think the problem is elsewhere in your code--in a part that isn't in the original question. Where are you actually encountering the exception? – Zenexer Feb 08 '12 at 02:28
  • (Note for other users: the code for the program can be found at http://pastebin.com/u/Jinfaa as the above link is malformed.) – Zenexer Feb 08 '12 at 02:30
  • There are no exceptions, only the application interface is not updated. As if the program creates a new customer. – Feor Feb 08 '12 at 02:30
  • I've been looking over the code, but I doubt I will find anything. I think you need to debug further on your own and come back here with a more specific problem; your question is a bit too vague at the moment. – Zenexer Feb 08 '12 at 02:38
  • So I'm trying to alter the program for WPF http://www.codeproject.com/Articles/10599/A-Chat-Server-Client-Solution-for-Local-Networks – Feor Feb 08 '12 at 02:45

1 Answers1

1

In mainwindow.xaml.cs, on line 240, change this.Dispatcher.BeginInvoke to this.Dispatcher.Invoke. BeginInvoke works some asynchronous voodoo that I've never been able to get to work properly. You're better off with plain old Invoke unless you have a specific reason to work asynchronously, which I rarely do.

Change you MainWindow class such that it extends Window.

Don't use CheckAccess().

Change the other BeginInvoke call such that the method is called directly from the same thread as the window or uses Invoke. I think it might already be in the same thread as the window. I haven't looked closely.

There are a lot of other small changes that you need to make; you are going to need to start over from scratch. You should learn WPF more in-depth before attempting something like this.

Zenexer
  • 18,788
  • 9
  • 71
  • 77
  • Then you found your problem. Whatever you are invoking hangs--or the invoke process itself hangs, which is just as bad. – Zenexer Feb 08 '12 at 03:02
  • No, it's not fully performed, otherwise the dispatcher wouldn't hang. Anyway, I updated my answer. – Zenexer Feb 08 '12 at 03:14