2012-02-08 2 views
1

WPF의 시작점은 어떻게 될까요?시작 지점 Winforms to 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); 

    } 

winforms 마샬링이 올바르게 작동하면 변환하고 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); 
    } 

나는 그렇게했지만, 프로그램 작업이 완전히 올바르지 않기 때문에 나는 옳은 것이 확실하지 않다.

pastebin.com/u/Jinfaa CODE http://screencast-o-matic.com/watch/clniI54tY 동영상

+0

코드를 직접 작성 했습니까? 아니면 변환기를 사용 했습니까? 당신이 변환기를 사용한 것 같습니다. 나는 그것을 반대하는 것이 좋습니다. – Zenexer

+0

나 자신을 썼다. – Feor

+0

그런 경우 DebuggerNonUserCode 속성을 제거해야합니다. – Zenexer

답변

1

MainWindow.xaml.cs를, 출력 라인 (240)에 this.Dispatcher.Invokethis.Dispatcher.BeginInvoke 변경. BeginInvoke은 제대로 작동하지 못하는 일부 비동기 부두가 작동합니다. 비공식적으로 작업해야하는 구체적인 이유가없는 한 평범한 오래된 Invoke을 사용하는 것이 나을 것입니다.

MainWindow 클래스가 Window으로 확장되도록 변경하십시오.

CheckAccess()을 사용하지 마십시오.

다른 BeginInvoke 호출을 변경하여 메서드가 창과 동일한 스레드에서 직접 호출되거나 Invoke을 사용합니다. 이미 윈도우와 같은 스레드에있을 수도 있습니다. 나는 가까이서 보지 않았다.

기타 약간의 변경이 필요합니다. 처음부터 다시 시작할 필요가 있습니다. 이런 식으로 시도하기 전에 WPF를 더 깊이 배워야합니다.

+0

프로그램이 응답하지 않습니다 ... – Feor

+0

그런 다음 문제를 발견했습니다. 호출하는 것이 무엇이든 중단됩니다. 또는 호출 프로세스 자체가 멈추는 것은 마찬가지입니다. – Zenexer

+0

실제로는 기능 자체는 수행되지만 Dispatcher에서는 중지됩니다. – Feor