簡體   English   中英

NDde Server和Context,用於多個主題和項目。 我需要多個實例嗎?

[英]NDde Server and Context for multiple Topics and Items. Do I need multiple instances?

我已經檢查了這個問題: Codeplex NDde Server如何發送多個項目 ,以及client.Advise + = OnAdvise的替代方案; 在vb.net NDDE和其他許多來源中,當處理此問題時; 但是似乎我不了解一些基礎知識,或者我嘗試這樣做的方式未明確支持它。

我正在努力編寫一個類庫,該類庫將向一些優先使用DDE輸入的應用程序發送一些值(大約六個)。

對我來說,困惑的根源是,是否我需要做這樣的事情,以便能夠通過熱鏈接發送我的物品

        public AutoServer(string service, string ItemDataLabel)
            : base(service)
        {
            // Create a timer that will be used to advise clients of new data.
            _Timer.Elapsed += this.OnTimerElapsed;
            _Timer.Interval = 30;
            _Timer.SynchronizingObject = this.Context;

            DataLabel = ItemDataLabel;
            //OnAdvise(Symbol, DataLabel, 1);
        }



        private void OnTimerElapsed(object sender, ElapsedEventArgs args)
        {
            // Advise all topic name and item name pairs.

            OnAdvise(Current, DataLabel, 1);

            Advise(Current, DataLabel);
        }


        public string Data;
        public string DataLabel;

}

並以這種方式放置幾個帶有不同字符串標簽的OnAdvises,寫出在OnAdvice本身內部每種標簽組合情況下On Advise應該做什么?

另一個選擇似乎是注冊幾個Server實例,並在OnAdvice中寫出每種情況下參數組合的所有詳細信息。 但這是最困難的。 我嘗試了這兩種方法,但是卻遇到異常提示:在創建窗口句柄之前,無法在控件上調用Invoke或BeginInvoke。 換句話說,我需要為每個服務器分別為每個項目都需要一個上下文(將多個OnAdvices放在一起的所有東西似乎都不起作用)。

那么,將形式和上下文初始化放在具有相應服務器注冊的單個方法中,以及與項目一樣多的相同方法,並同時運行它們是否正確?

例如:

namespace lookout_DDE
{
    public partial class lookout_DDE_class : AutoGroup
    {


        public partial class ServerContextForm : Form
        {
            private DdeContext context = null;

            private void ContextRunner()
            {
                context = new DdeContext(this);
                context.Initialize();
            }             
        }
    }
}

namespace lookout_DDE
{
    public partial class lookout_DDE_class : AutoGroup
    {
        public partial class ServerContextForm : Form
        {
            public ServerContextForm()
            {
                InitializeComponent();
                ContextRunner();
            }
        }
    }
}

        [STAThread]
        partial void RunServer()
        {

            using (ServerContextForm ContextForm = new ServerContextForm())
            {
                Application.Run(ContextForm);
                ServerStarter("A1");
            }
            using (ServerContextForm ContextForm = new ServerContextForm())
            {
                Application.Run(ContextForm);

                ServerStarter("A2");
            }
            using (ServerContextForm ContextForm = new ServerContextForm())
            {
                Application.Run(ContextForm);

                ServerStarter("A3");
            }
            using (ServerContextForm ContextForm = new ServerContextForm())
            {
                Application.Run(ContextForm);

                ServerStarter("A4");
            }
            using (ServerContextForm ContextForm = new ServerContextForm())
            {
                Application.Run(ContextForm);

                ServerStarter("A5");
            }
}

剛發現我必須保留Forms才能運行上下文,因此需要\\ using \\單獨的方法。

因此,重述此問題的最佳方法可能是:是否需要使用具有上下文的多種形式以及注冊的服務器實例,以便運行多個項目,還是應該在Server類內部實現OnAdvice?

看,我是C#和一般編程的新手,但是,我正在嘗試“在過程中”學習編程。 如果可以幫助,請指教。 :)

到現在為止,已經找到了部分解決方案:1)需要有多個Server實例,因為OnAdvice可以由客戶端應用程序一次訂閱。 (如果您不編寫它,誰知道它是如何做到的)2)每個服務器可能需要一個單獨的(首選)上下文,以及一個表單,但是可能存在一個單獨的上下文。 沒有測試最后一個。

現在,我回想起“潛在”一詞的好/壞笑話。 你猜怎么了。 真可惜根本沒有意見!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM