{"id":8040,"date":"2025-09-04T23:22:33","date_gmt":"2025-09-05T04:22:33","guid":{"rendered":"https:\/\/librarytestdev.wpenginepowered.com\/?post_type=doc&#038;p=8040"},"modified":"2025-09-04T23:23:55","modified_gmt":"2025-09-05T04:23:55","slug":"initializing-a-ui-application","status":"publish","type":"doc","link":"https:\/\/library-staging.tradingtechnologies.com\/apis\/tt-net-sdk\/creating-the-application-framework\/initializing-a-ui-application\/","title":{"rendered":"Initializing a UI application"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">To create a UI application, you need to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create an instance of the\u00a0<a href=\"\/tt-net-sdk\/api\/tt_net_sdk.TTAPIOptions.html\">TTAPIOptions<\/a>\u00a0class passing the TT environment to which your application will connect, your application key for this environment, and a timeout interval.TT recommends setting the value of the Timeout interval to 5000 milliseconds.<\/li>\n\n\n\n<li>Attach a UI dispatcher to the UI thread on which you will consume events and start it.<\/li>\n\n\n\n<li>Initialize TT .NET SDK.<\/li>\n\n\n\n<li>Authenticate your credentials.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"client-side-mode-example\"><a href=\"\/tt-net-sdk\/articles\/af-forms-app.html#client-side-mode-example\"><\/a>Client-side mode example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The following code snippet demonstrates an example of this process for client-side mode.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ ...\n\nusing tt_net_sdk;\n\n\/\/ ...\n\nstatic class Program\n{\n  &#91;STAThread]\n  static void Main()\n  {\n        using (Dispatcher disp = Dispatcher.AttachUIDispatcher())\n        {\n            Application.EnableVisualStyles();\n            \n            \/\/ Create an instance of the API\n            MyApp myApp = new MyApp();\n\n            \/\/ Add your app secret Key here. It looks like: 00000000-0000-0000-0000-000000000000:00000000-0000-0000-0000-000000000000\n            string appSecretKey = \"you app key here\";\n\n            tt_net_sdk.ServiceEnvironment environment = tt_net_sdk.ServiceEnvironment.UatCert;\n            tt_net_sdk.TTAPIOptions apiConfig = new tt_net_sdk.TTAPIOptions(environment, appSecretKey, 5000);\n\n            apiConfig.BinaryProtocol = true;\n\n            ApiInitializeHandler handler = new ApiInitializeHandler(myApp.ttNetApiInitHandler);\n            TTAPI.CreateTTAPI(disp, apiConfig, handler);\n\n            Application.Run(myApp);\n        }\n  }\n}\n\n\n\/\/ ...\n\nusing tt_net_sdk;\n\n\/\/ ...\n\npublic partial class MyApp : Form\n{\n    \/\/ Declare the API objects\n    private TTAPI m_api = null;\n    private bool m_isShutdown = false, m_shutdownInProcess = false;\n\n\n    public MyApp()\n    {\n        InitializeComponent();\n    }\n\n    public void ttNetApiInitHandler(TTAPI api, ApiCreationException ex)\n    {\n        if (ex == null)\n        {\n            \/\/ TT NET SDK INITIALIZED\n            m_api = api;\n            m_api.TTAPIStatusUpdate += new EventHandler&lt;TTAPIStatusUpdateEventArgs&gt;(m_api_TTAPIStatusUpdate);\n            m_api.Start();\n        }\n        else if (ex.IsRecoverable)\n        {\n            \/\/ Initialization failed but retry is in progress...\n        }\n        else\n        {\n            MessageBox.Show(\"API Initialization Failed: \" + ex.Message);\n        }\n    }\n\n    private void m_api_TTAPIStatusUpdate(object sender, TTAPIStatusUpdateEventArgs e)\n    {\n        if (e.IsReady)\n        {\n            \/\/ connection to TT is established\n        }\n        else if (ex.IsDown)\n        {\n            \/\/ connection is down but TT .NET SDK will automatically attempt to reconnect \n        }\n        else\n        {\n            MessageBox.Show(String.Format(\"M_TTAPI_TTAPIStatusUpdate: {0}\", e));\n        }\n    }\n\n    public void shutdownTTAPI()\n    {\n        if (!m_shutdownInProcess)\n        {\n            TTAPI.ShutdownCompleted += new EventHandler(TTAPI_ShutdownCompleted);\n            TTAPI.Shutdown();\n\n            m_shutdownInProcess = true;\n        }\n    }\n\n    public void TTAPI_ShutdownCompleted(object sender, EventArgs e)\n    {\n        m_isShutdown = true;\n        Close();\n    }\n\n    protected override void OnFormClosing(FormClosingEventArgs e)\n    {\n        if (!m_isShutdown)\n        {\n            e.Cancel = true;\n            shutdownTTAPI();\n        }\n        else\n        {\n            base.OnFormClosing(e);\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"server-side-mode-example\"><a href=\"\/tt-net-sdk\/articles\/af-forms-app.html#server-side-mode-example\"><\/a>Server-side mode example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The following code snippet demonstrates an example of this process for server-side mode.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ ...\n\nusing tt_net_sdk;\n\n\/\/ ...\n\nstatic class Program\n{\n  &#91;STAThread]\n  static void Main()\n  {\n        using (Dispatcher disp = Dispatcher.AttachUIDispatcher())\n        {\n            Application.EnableVisualStyles();\n            \n            \/\/ Create an instance of the API\n            MyApp myApp = new MyApp();\n\n            \/\/ Add your app secret Key here. It looks like: 00000000-0000-0000-0000-000000000000:00000000-0000-0000-0000-000000000000\n            string appSecretKey = \"you app key here\";\n\n            tt_net_sdk.ServiceEnvironment environment = tt_net_sdk.ServiceEnvironment.UatCert;\n            tt_net_sdk.TTAPIOptions apiConfig = new tt_net_sdk.TTAPIOptions(\n                    tt_net_sdk.TTAPIOptions.SDKMode.Server, environment, appSecretKey, 5000);\n            apiConfig.ServerInstanceId = \u201c&lt;InstanceIdAssignedToYourMachineByTT&gt;\u201d;\n\n            ApiInitializeHandler handler = new ApiInitializeHandler(myApp.ttNetApiInitHandler);\n            TTAPI.CreateTTAPI(disp, apiConfig, handler);\n\n            Application.Run(myApp);\n        }\n  }\n}\n\n\n\/\/ ...\n\nusing tt_net_sdk;\n\n\/\/ ...\n\npublic partial class MyApp : Form\n{\n    \/\/ Declare the API objects\n    private TTAPI m_api = null;\n    private bool m_isShutdown = false, m_shutdownInProcess = false;\n\n\n    public MyApp()\n    {\n        InitializeComponent();\n    }\n\n    public void ttNetApiInitHandler(TTAPI api, ApiCreationException ex)\n    {\n        if (ex == null)\n        {\n            Console.WriteLine(\"TT.NET SDK Initialization Complete\");\n            \/\/ Authenticate your credentials\n            m_api = api;\n            m_api.TTAPIStatusUpdate += new EventHandler&lt;TTAPIStatusUpdateEventArgs&gt;(m_api_TTAPIStatusUpdate);\n            m_api.Start();\n        }\n        else if (ex.IsRecoverable)\n        {\n            \/\/ this is in informational update from the SDK\n            Console.WriteLine(\"TT.NET SDK Initialization Message: {0}\", ex.Message);\n            if (ex.Code == ApiCreationException.ApiCreationError.NewAPIVersionAvailable)\n            {\n                \/\/ a newer version of the SDK is available - notify someone to upgrade\n            }\n        }\n        else\n        {\n            Console.WriteLine(\"TT.NET SDK Initialization Failed: {0}\", ex.Message);\n            if (ex.Code == ApiCreationException.ApiCreationError.NewAPIVersionRequired)\n            {\n                \/\/ do something to upgrade the SDK package since it will not start until it is upgraded \n                \/\/ to the minimum version noted in the exception message\n            }\n            Dispose();\n        }\n    }\n\n    private void m_api_TTAPIStatusUpdate(object sender, TTAPIStatusUpdateEventArgs e)\n    {\n        if (e.IsReady)\n        {\n            \/\/ connection to TT is established\n        }\n        else if (ex.IsDown)\n        {\n            \/\/ connection is down but TT .NET SDK will automatically attempt to reconnect \n        }\n        else\n        {\n            MessageBox.Show(String.Format(\"M_TTAPI_TTAPIStatusUpdate: {0}\", e));\n        }\n    }\n\n    public void shutdownTTAPI()\n    {\n        if (!m_shutdownInProcess)\n        {\n            TTAPI.ShutdownCompleted += new EventHandler(TTAPI_ShutdownCompleted);\n            TTAPI.Shutdown();\n\n            m_shutdownInProcess = true;\n        }\n    }\n\n    public void TTAPI_ShutdownCompleted(object sender, EventArgs e)\n    {\n        m_isShutdown = true;\n        Close();\n    }\n\n    protected override void OnFormClosing(FormClosingEventArgs e)\n    {\n        if (!m_isShutdown)\n        {\n            e.Cancel = true;\n            shutdownTTAPI();\n        }\n        else\n        {\n            base.OnFormClosing(e);\n        }\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>To create a UI application, you need to: Client-side mode example The following code snippet demonstrates an e [&hellip;]<\/p>\n","protected":false},"author":2,"template":"wp-custom-template-single-doc-tt-net-sdk","meta":{"_acf_changed":true,"footnotes":""},"docs-category":[770],"class_list":["post-8040","doc","type-doc","status-publish","hentry","docs-category-creating-the-application-framework"],"acf":[],"_links":{"self":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc\/8040","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc"}],"about":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/types\/doc"}],"author":[{"embeddable":true,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/users\/2"}],"version-history":[{"count":0,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/doc\/8040\/revisions"}],"wp:attachment":[{"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/media?parent=8040"}],"wp:term":[{"taxonomy":"docs-category","embeddable":true,"href":"https:\/\/library-staging.tradingtechnologies.com\/ja\/wp-json\/wp\/v2\/docs-category?post=8040"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}